Class GooglePlacesProvider
- All Implemented Interfaces:
PlacesProvider
Place search over the Google Places API (New) REST endpoints:
places:autocomplete and place details.
Requests in one search share a session token, so Google bills the autocomplete requests and the details request as one session. The key needs the Places API (New) enabled; restrict it to your apps in the Google Cloud console.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionautocomplete(String input, String sessionToken, LatLng bias) Suggests places for partial input.getDetails(String placeId, String sessionToken) Resolves a suggestion.static PlaceDetailsparseDetails(Map<String, Object> json) Reads a place details response.static List<PlacePrediction> parsePredictions(Map<String, Object> json) Reads the predictions of aplaces:autocompleteresponse.voidsetBiasRadius(double meters) Sets the radius of the location bias in meters.voidsetLanguageCode(String languageCode) Sets the language of results,enorfrfor example.voidsetTransport(CloudHttpTransport transport) Replaces the HTTP transport, for tests or a custom stack.
-
Constructor Details
-
GooglePlacesProvider
Creates the provider.
Parameters
apiKey: a Google API key with the Places API (New) enabled
-
-
Method Details
-
setTransport
Replaces the HTTP transport, for tests or a custom stack.
Parameters
transport: the transport
-
setLanguageCode
Sets the language of results,
enorfrfor example.Parameters
languageCode: a BCP-47 code, or null for the default
-
setBiasRadius
public void setBiasRadius(double meters) Sets the radius of the location bias in meters. The default is 50 km.
Parameters
meters: the radius
-
autocomplete
public AsyncResource<List<PlacePrediction>> autocomplete(String input, String sessionToken, LatLng bias) Description copied from interface:PlacesProviderSuggests places for partial input.
Parameters
-
input: what the user typed -
sessionToken: groups the requests of one search for billing; may be ignored -
bias: prefers results near this point, may be null
Returns
the suggestions
- Specified by:
autocompletein interfacePlacesProvider
-
-
getDetails
Description copied from interface:PlacesProviderResolves a suggestion. This ends the session the token names.
Parameters
-
placeId: the ID of a prediction -
sessionToken: the token used for the autocomplete requests
Returns
the details
- Specified by:
getDetailsin interfacePlacesProvider
-
-
parsePredictions
Reads the predictions of a
places:autocompleteresponse.Parameters
json: the parsed response
Returns
the place predictions; query predictions are skipped
-
parseDetails
Reads a place details response.
Parameters
json: the parsed response
Returns
the details, or null when the response has no ID
-