geocodeAutoCompleteGet method
Future<GeoJsonFeatureCollection>
geocodeAutoCompleteGet({
- required String text,
- ORSCoordinate? focusPointCoordinate,
- ORSCoordinate? boundaryRectangleMinCoordinate,
- ORSCoordinate? boundaryRectangleMaxCoordinate,
- String? boundaryCountry,
- List<
String> ? sources, - List<
String> layers = const <String>[],
Fetches the Geocode Autocomplete data for the given text
from chosen
sources
and using settings layers
, and returns the entire geojson
GeoJsonFeatureCollection
containing the data.
Can be constrained using the various ORSCoordinate parameters.
GeoJsonFeatureCollection
-> GeoJsonFeatureCollection.features
is a list of GeoJsonFeatures whose GeoJsonFeature.properties have all
the information about the result of the autocomplete query.
Information about the endpoint, parameters, response etc. can be found at:
https://openrouteservice.org/dev/#/api-docs/geocode/autocomplete/get
https://github.com/pelias/documentation/blob/master/autocomplete.md
Implementation
Future<GeoJsonFeatureCollection> geocodeAutoCompleteGet({
required String text,
ORSCoordinate? focusPointCoordinate,
ORSCoordinate? boundaryRectangleMinCoordinate,
ORSCoordinate? boundaryRectangleMaxCoordinate,
String? boundaryCountry,
List<String>? sources,
List<String> layers = const <String>[],
}) async {
// Validate input.
_bothOrNeitherNullValidation(
boundaryRectangleMinCoordinate,
boundaryRectangleMaxCoordinate,
);
// Form input from parameters.
sources ??= geocodeSourcesAvailable.toList();
final String sourcesString = _validateAndJoinList(
inputArr: sources,
availableIterable: geocodeSourcesAvailable,
);
final String layersString = _validateAndJoinList(
inputArr: layers,
availableIterable: geocodeLayersAvailable,
);
String getURIString =
'$_geocodeEndpointURL/autocomplete?api_key=$_apiKey&text=$text&sources=$sourcesString';
if (layersString.isNotEmpty) {
getURIString += '&layers=$layersString';
}
if (focusPointCoordinate != null) {
getURIString += '&focus.point.lon=${focusPointCoordinate.longitude}';
getURIString += '&focus.point.lat=${focusPointCoordinate.latitude}';
}
if (boundaryRectangleMinCoordinate != null) {
getURIString +=
'&boundary.rect.min_lon=${boundaryRectangleMinCoordinate.longitude}';
getURIString +=
'&boundary.rect.min_lat=${boundaryRectangleMinCoordinate.latitude}';
}
if (boundaryRectangleMaxCoordinate != null) {
getURIString +=
'&boundary.rect.max_lon=${boundaryRectangleMaxCoordinate.longitude}';
getURIString +=
'&boundary.rect.max_lat=${boundaryRectangleMaxCoordinate.latitude}';
}
if (boundaryCountry != null) {
getURIString += '&boundary.country=$boundaryCountry';
}
// Build the request URL.
final Uri uri = Uri.parse(getURIString);
final Map<String, dynamic> data = await _openRouteServiceGet(uri: uri);
return GeoJsonFeatureCollection.fromJson(data);
}