The autocomplete service in the Google Places API for Android returns place predictions in response to a text-based location search query. The request includes a textual search string and optional filter criteria. You can use this service to provide autocomplete functionality as the user types, by returning places such as businesses, addresses and points of interest.
Get place predictions
To get a list of predicted place names and/or addresses, call
passing the following parameters:
- Required: A
querystring containing the text typed by the user.
- Required: A
LatLngBoundsobject, biasing the results to a specific area specified by latitude and longitude bounds.
- Optional: An
AutocompleteFiltercontaining a set of place types, which you can use to restrict the results to one or more types of place. The following place types are supported in the filter:
geocode– Returns only geocoding results, rather than businesses. Generally, you use this request to disambiguate results where the location specified may be indeterminate.
address– Returns only autocomplete results with a precise address. Generally, you use this request when you know the user will be looking for a fully specified address.
establishment– Returns only places that are businesses.
For information about place types in general, see the guide to place types.
result = Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient, query, mBounds, mAutocompleteFilter);
The API returns an
contains a list of
objects representing predicted places. The buffer may be empty, if there is no
known place corresponding to the query and the filter criteria.
For each predicted place, you can call the following methods to retrieve place details:
getDescription()– Returns the description of the place.
getMatchedSubstrings()– Returns a list of the substrings from the
querythat match this place. You can use these substrings to highlight the matching text in the user's query, for example.
getPlaceId()– Returns the place ID of the predicted place. A place ID is a textual identifier that uniquely identifies a place. For more information about place IDs, see the place ID overview.
getPlaceTypes()– Returns the list of place types associated with this place.
Display attributions in your app
If your app uses the autocomplete service, you must display a 'Powered by Google' attribution. If you retrieve and display additional place information after getting a place by ID, you must display third-party attributions too. See the documentation on attributions.