Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public class GooglePlacesProvider
- Object
- GooglePlacesProvider
ImplementsPlacesProvider
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.
Constructors
public GooglePlacesProvider(String apiKey) | Creates the provider. |
Methods
Inherited methods
Constructor details
GooglePlacesProvider
public GooglePlacesProvider(String apiKey)Creates the provider.
Parameters
apiKeyString- a Google API key with the Places API (New) enabled
Method details
setTransport
public void setTransport(CloudHttpTransport transport)Replaces the HTTP transport, for tests or a custom stack.
Parameters
transportCloudHttpTransport- the transport
setLanguageCode
public void setLanguageCode(String languageCode)Sets the language of results,
en or fr for example.Parameters
languageCodeString- 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
metersdouble- the radius
autocomplete
public AsyncResource<List<PlacePrediction>> autocomplete(String input, String sessionToken, LatLng bias)Suggests places for partial input.
Parameters
inputString- what the user typed
sessionTokenString- groups the requests of one search for billing; may be ignored
biasLatLng- prefers results near this point, may be null
Returns
the suggestions
getDetails
public AsyncResource<PlaceDetails> getDetails(String placeId, String sessionToken)Resolves a suggestion. This ends the session the token names.
Parameters
placeIdString- the ID of a prediction
sessionTokenString- the token used for the autocomplete requests
Returns
the details
parsePredictions
public static List<PlacePrediction> parsePredictions(Map<String, Object> json)Reads the predictions of a
places:autocomplete response.Parameters
jsonMap<String, Object>- the parsed response
Returns
the place predictions; query predictions are skipped
parseDetails
public static PlaceDetails parseDetails(Map<String, Object> json)Reads a place details response.
Parameters
jsonMap<String, Object>- the parsed response
Returns
the details, or null when the response has no ID