Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public class GooglePlacesProvider

  1. Object
  2. 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

public void setTransport(CloudHttpTransport transport)Replaces the HTTP transport, for tests or a custom stack.
public void setLanguageCode(String languageCode)Sets the language of results, en or fr for example.
public void setBiasRadius(double meters)Sets the radius of the location bias in meters.
public AsyncResource<List<PlacePrediction>> autocomplete(String input, String sessionToken, LatLng bias)Suggests places for partial input.
public AsyncResource<PlaceDetails> getDetails(String placeId, String sessionToken)Resolves a suggestion.
public static List<PlacePrediction> parsePredictions(Map<String, Object> json)Reads the predictions of a places:autocomplete response.
public static PlaceDetails parseDetails(Map<String, Object> json)Reads a place details response.

Inherited methods

Constructor details

GooglePlacesProvider

public GooglePlacesProvider(String apiKey)
Creates the provider.

Parameters

apiKey String
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

transport CloudHttpTransport
the transport

setLanguageCode

public void setLanguageCode(String languageCode)
Sets the language of results, en or fr for example.

Parameters

languageCode String
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 double
the radius

autocomplete

public AsyncResource<List<PlacePrediction>> autocomplete(String input, String sessionToken, LatLng bias)
Suggests places for partial input.

Parameters

input String
what the user typed
sessionToken String
groups the requests of one search for billing; may be ignored
bias LatLng
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

placeId String
the ID of a prediction
sessionToken String
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

json Map<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

json Map<String, Object>
the parsed response

Returns

the details, or null when the response has no ID