searchNearby method

Future<SearchNearbyResponse> searchNearby({
  1. required List<double> queryPosition,
  2. List<SearchNearbyAdditionalFeature>? additionalFeatures,
  3. SearchNearbyFilter? filter,
  4. SearchNearbyIntendedUse? intendedUse,
  5. String? key,
  6. String? language,
  7. int? maxResults,
  8. String? nextToken,
  9. String? politicalView,
  10. int? queryRadius,
})

SearchNearby queries for points of interest within a radius from a central coordinates, returning place results with optional filters such as categories, business chains, food types and more. The API returns details such as a place name, address, phone, category, food type, contact, opening hours. Also, the API can return phonemes, time zones and more based on requested parameters.

For more information, see Search Nearby in the Amazon Location Service Developer Guide.

May throw AccessDeniedException. May throw InternalServerException. May throw ThrottlingException. May throw ValidationException.

Parameter queryPosition : The position in World Geodetic System (WGS 84) format: [longitude, latitude] for which you are querying nearby results for. Results closer to the position will be ranked higher then results further away from the position

Parameter additionalFeatures : A list of optional additional parameters, such as time zone, that can be requested for each result.

Parameter filter : A structure which contains a set of inclusion/exclusion properties that results must possess in order to be returned as a result.

Parameter intendedUse : Indicates if the query results will be persisted in customer infrastructure. Defaults to SingleUse (not stored). Not supported in ap-southeast-1 and ap-southeast-5 regions for GrabMaps customers.

Parameter key : Optional: The API key to be used for authorization. Either an API key or valid SigV4 signature must be provided when making a request.

Parameter language : A list of BCP 47 compliant language codes for the results to be rendered in. If there is no data for the result in the requested language, data will be returned in the default language for the entry.

Parameter maxResults : An optional limit for the number of results returned in a single call.

Default value: 20

Parameter nextToken : If nextToken is returned, there are more results available. The value of nextToken is a unique pagination token for each page.

Parameter politicalView : The alpha-2 or alpha-3 character code for the political view of a country. The political view applies to the results of the request to represent unresolved territorial claims through the point of view of the specified country.

Parameter queryRadius : The maximum distance in meters from the QueryPosition from which a result will be returned.

Implementation

Future<SearchNearbyResponse> searchNearby({
  required List<double> queryPosition,
  List<SearchNearbyAdditionalFeature>? additionalFeatures,
  SearchNearbyFilter? filter,
  SearchNearbyIntendedUse? intendedUse,
  String? key,
  String? language,
  int? maxResults,
  String? nextToken,
  String? politicalView,
  int? queryRadius,
}) async {
  _s.validateNumRange(
    'queryRadius',
    queryRadius,
    0,
    4294967295,
  );
  final $query = <String, List<String>>{
    if (key != null) 'key': [key],
  };
  final $payload = <String, dynamic>{
    'QueryPosition': queryPosition.map(_s.encodeJsonDouble).toList(),
    if (additionalFeatures != null)
      'AdditionalFeatures': additionalFeatures.map((e) => e.value).toList(),
    if (filter != null) 'Filter': filter,
    if (intendedUse != null) 'IntendedUse': intendedUse.value,
    if (language != null) 'Language': language,
    if (maxResults != null) 'MaxResults': maxResults,
    if (nextToken != null) 'NextToken': nextToken,
    if (politicalView != null) 'PoliticalView': politicalView,
    if (queryRadius != null) 'QueryRadius': queryRadius,
  };
  final response = await _protocol.sendRaw(
    payload: $payload,
    method: 'POST',
    requestUri: '/v2/search-nearby',
    queryParams: $query,
    exceptionFnMap: _exceptionFns,
  );
  final $json = await _s.jsonFromResponse(response);
  return SearchNearbyResponse(
    nextToken: $json['NextToken'] as String?,
    resultItems: ($json['ResultItems'] as List?)
        ?.nonNulls
        .map(
            (e) => SearchNearbyResultItem.fromJson(e as Map<String, dynamic>))
        .toList(),
    pricingBucket: _s.extractHeaderStringValue(
        response.headers, 'x-amz-geo-pricing-bucket')!,
  );
}