queryAutocomplete method
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 "pizza near New York" 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 isGoogle
and the offset is 3, the service will match onGoo
. The string determined by the offset is matched against the first word in the input term only. For example, if the input term isGoogle abc
and the offset is 3, the service will attempt to match againstGoo 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 aslatitude,longitude
. <div class="note">Thelocation
parameter may be overriden if thequery
contains an explicit location such asMarket in Barcelona
. Using quotes around the query may also influence the weight given to thelocation
andradius
.radius
- Defines the distance (in meters) within which to return place results. You may bias results to a specified circle by passing alocation
and aradius
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: * withkeyword
orname
: 50,000 meters * withoutkeyword
orname
*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 meterslanguage
- 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. * Iflanguage
is not supplied, the API attempts to use the preferred language as specified in theAccept-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
- ACancelToken
that can be used to cancel the operationheaders
- Can be used to add additional headers to the requestextras
- Can be used to add flags to the requestvalidateStatus
- AValidateStatus
callback that can be used to determine request success based on the HTTP status of the responseonSendProgress
- AProgressCallback
that can be used to get the send progressonReceiveProgress
- AProgressCallback
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,
);
}