findAutocompletePredictions method
Future<FindAutocompletePredictionsResponse>
findAutocompletePredictions(
- String query, {
- List<
String> ? countries, - List<
String> placeTypesFilter = const [], - bool? newSessionToken,
- LatLng? origin,
- LatLngBounds? locationBias,
- LatLngBounds? locationRestriction,
inherited
Fetches autocomplete predictions based on a query.
If countries
] is not null, the results are restricted to those countries.
AutocompletePrediction.distanceMeters
is calculated from origin
,
if available. If origin
is null, no distances will be included in the
response.
When making multiple requests, a session token is saved on one request and the same is sent to the following ones
If newSessionToken
is null, a previously-saved session token will be used.
If there is no previously-saved session token exist, a request without
a session token will be saved and the result token will be saved.
For more about session tokens: https://developers.google.com/maps/documentation/places/android-sdk/session-tokens
Implementation
@override
Future<inter.FindAutocompletePredictionsResponse> findAutocompletePredictions(
String query, {
List<String>? countries,
List<String> placeTypesFilter = const [],
bool? newSessionToken,
inter.LatLng? origin,
inter.LatLngBounds? locationBias,
inter.LatLngBounds? locationRestriction,
}) async {
final sessionToken = (newSessionToken ?? false) ? null : _lastSessionToken;
final url = _buildAutocompleteUrl(query, countries, placeTypesFilter,
sessionToken, origin, locationBias, locationRestriction);
final PlacesAutocompleteResponse response =
await _doGet(url, (json) => PlacesAutocompleteResponse.fromJson(json));
if (response.status != PlacesAutocompleteStatus.OK &&
response.status != PlacesAutocompleteStatus.ZERO_RESULTS) {
throw response;
}
final predictions = response.predictions
.map((e) => e.toInterface())
.toList(growable: false);
return inter.FindAutocompletePredictionsResponse(predictions);
}