Class GooglePlacesProvider

java.lang.Object
com.codename1.maps.places.GooglePlacesProvider
All Implemented Interfaces:
PlacesProvider

public class GooglePlacesProvider extends Object implements 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 Details

    • GooglePlacesProvider

      public GooglePlacesProvider(String apiKey)

      Creates the provider.

      Parameters
      • apiKey: 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: the transport
    • setLanguageCode

      public void setLanguageCode(String languageCode)

      Sets the language of results, en or fr for 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: PlacesProvider

      Suggests 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:
      autocomplete in interface PlacesProvider
    • getDetails

      public AsyncResource<PlaceDetails> getDetails(String placeId, String sessionToken)
      Description copied from interface: PlacesProvider

      Resolves 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:
      getDetails in interface PlacesProvider
    • parsePredictions

      public static List<PlacePrediction> parsePredictions(Map<String,Object> json)

      Reads the predictions of a places:autocomplete response.

      Parameters
      • json: 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: the parsed response
      Returns

      the details, or null when the response has no ID