queryAutocomplete method

Future<Response<PlacesQueryAutocompleteResponse>> queryAutocomplete({
  1. required String input,
  2. num? offset,
  3. String? location,
  4. num? radius,
  5. String? language = 'en',
  6. CancelToken? cancelToken,
  7. Map<String, dynamic>? headers,
  8. Map<String, dynamic>? extra,
  9. ValidateStatus? validateStatus,
  10. ProgressCallback? onSendProgress,
  11. ProgressCallback? onReceiveProgress,
})

queryAutocomplete The Query Autocomplete service can be used to provide a query prediction for text-based geographic searches, by returning suggested queries as you type. The Query Autocomplete service allows you to add on-the-fly geographic query predictions to your application. Instead of searching for a specific location, a user can type in a categorical search, such as &quot;pizza near New York&quot; and the service responds with a list of suggested queries matching the string. As the Query Autocomplete service can match on both full words and substrings, applications can send queries as the user types to provide on-the-fly predictions.

Parameters:

  • input - The text string on which to search. The Place Autocomplete service will return candidate matches based on this string and order results based on their perceived relevance.
  • offset - The position, in the input term, of the last character that the service uses to match predictions. For example, if the input is Google and the offset is 3, the service will match on Goo. The string determined by the offset is matched against the first word in the input term only. For example, if the input term is Google abc and the offset is 3, the service will attempt to match against Goo abc. If no offset is supplied, the service will use the whole term. The offset should generally be set to the position of the text caret.
  • location - The point around which to retrieve place information. This must be specified as latitude,longitude. <div class="note">The location parameter may be overriden if the query contains an explicit location such as Market in Barcelona. Using quotes around the query may also influence the weight given to the location and radius.
  • radius - Defines the distance (in meters) within which to return place results. You may bias results to a specified circle by passing a location and a radius parameter. Doing so instructs the Places service to prefer showing results within that circle; results outside of the defined area may still be displayed. The radius will automatically be clamped to a maximum value depending on the type of search and other parameters. * Autocomplete: 50,000 meters * Nearby Search: * with keyword or name: 50,000 meters * without keyword or name * rankby=prominence (default): 50,000 meters * rankby=distance: A few kilometers depending on density of area * Query Autocomplete: 50,000 meters * Text Search: 50,000 meters
  • language - The language in which to return results. * See the list of supported languages. Google often updates the supported languages, so this list may not be exhaustive. * If language is not supplied, the API attempts to use the preferred language as specified in the Accept-Language header. * The API does its best to provide a street address that is readable for both the user and locals. To achieve that goal, it returns street addresses in the local language, transliterated to a script readable by the user if necessary, observing the preferred language. All other addresses are returned in the preferred language. Address components are all returned in the same language, which is chosen from the first component. * If a name is not available in the preferred language, the API uses the closest match. * The preferred language has a small influence on the set of results that the API chooses to return, and the order in which they are returned. The geocoder interprets abbreviations differently depending on language, such as the abbreviations for street types, or synonyms that may be valid in one language but not in another. For example, utca and tér are synonyms for street in Hungarian.
  • cancelToken - A CancelToken that can be used to cancel the operation
  • headers - Can be used to add additional headers to the request
  • extras - Can be used to add flags to the request
  • validateStatus - A ValidateStatus callback that can be used to determine request success based on the HTTP status of the response
  • onSendProgress - A ProgressCallback that can be used to get the send progress
  • onReceiveProgress - A ProgressCallback that can be used to get the receive progress

Returns a Future containing a Response with a PlacesQueryAutocompleteResponse as data Throws DioError if API call or serialization fails

Implementation

Future<Response<PlacesQueryAutocompleteResponse>> queryAutocomplete({
  required String input,
  num? offset,
  String? location,
  num? radius,
  String? language = 'en',
  CancelToken? cancelToken,
  Map<String, dynamic>? headers,
  Map<String, dynamic>? extra,
  ValidateStatus? validateStatus,
  ProgressCallback? onSendProgress,
  ProgressCallback? onReceiveProgress,
}) async {
  final _path = r'/maps/api/place/queryautocomplete/json';
  final _options = Options(
    method: r'GET',
    headers: <String, dynamic>{
      ...?headers,
    },
    extra: <String, dynamic>{
      'secure': <Map<String, String>>[
        {
          'type': 'apiKey',
          'name': 'ApiKeyAuth',
          'keyName': 'key',
          'where': 'query',
        },
      ],
      ...?extra,
    },
    validateStatus: validateStatus,
  );

  final _queryParameters = <String, dynamic>{
    r'input':
        encodeQueryParameter(_serializers, input, const FullType(String)),
    if (offset != null)
      r'offset':
          encodeQueryParameter(_serializers, offset, const FullType(num)),
    if (location != null)
      r'location': encodeQueryParameter(
          _serializers, location, const FullType(String)),
    if (radius != null)
      r'radius':
          encodeQueryParameter(_serializers, radius, const FullType(num)),
    if (language != null)
      r'language': encodeQueryParameter(
          _serializers, language, const FullType(String)),
  };

  final _response = await _dio.request<Object>(
    _path,
    options: _options,
    queryParameters: _queryParameters,
    cancelToken: cancelToken,
    onSendProgress: onSendProgress,
    onReceiveProgress: onReceiveProgress,
  );

  PlacesQueryAutocompleteResponse _responseData;

  try {
    const _responseType = FullType(PlacesQueryAutocompleteResponse);
    _responseData = _serializers.deserialize(
      _response.data!,
      specifiedType: _responseType,
    ) as PlacesQueryAutocompleteResponse;
  } catch (error, stackTrace) {
    throw DioError(
      requestOptions: _response.requestOptions,
      response: _response,
      type: DioErrorType.other,
      error: error,
    )..stackTrace = stackTrace;
  }

  return Response<PlacesQueryAutocompleteResponse>(
    data: _responseData,
    headers: _response.headers,
    isRedirect: _response.isRedirect,
    requestOptions: _response.requestOptions,
    redirects: _response.redirects,
    statusCode: _response.statusCode,
    statusMessage: _response.statusMessage,
    extra: _response.extra,
  );
}