findAutocompletePredictions method
Future<FindAutocompletePredictionsResponse>
findAutocompletePredictions(
- String query, {
- List<
String> ? countries, - List<
String> placeTypesFilter = const [], - bool? newSessionToken,
- LatLng? origin,
- LatLngBounds? locationBias,
- LatLngBounds? locationRestriction,
override
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<FindAutocompletePredictionsResponse> findAutocompletePredictions(
String query, {
List<String>? countries,
List<String> placeTypesFilter = const [],
bool? newSessionToken,
inter.LatLng? origin,
inter.LatLngBounds? locationBias,
inter.LatLngBounds? locationRestriction,
}) async {
await _completer;
if (locationRestriction != null) {
// https://issuetracker.google.com/issues/36219203
log("locationRestriction is not supported: https://issuetracker.google.com/issues/36219203");
}
final prom = _svcAutoComplete!.getPlacePredictions(AutocompletionRequest()
..input = query
..origin = origin == null ? null : core.LatLng(origin.lat, origin.lng)
..types = placeTypesFilter.isEmpty ? null : placeTypesFilter
..componentRestrictions = (ComponentRestrictions()..country = countries?.jsify())
..bounds = _boundsToWeb(locationBias)
..language = _language);
final resp = await prom;
final predictions = resp.predictions
.whereNotNull()
.map(_translatePrediction)
.toList(growable: false);
return FindAutocompletePredictionsResponse(predictions);
}