Places

public final class Places


Entry point for the Places API.

Summary

Public methods

synchronized static PlacesClient

Gets an instance of PlacesClient for a given Context.

synchronized static void

Deinitializes Places.

static void
initialize(Context applicationContext, String apiKey)

Initializes Places for the given application context with the given API key.

static void
initialize(
    Context applicationContext,
    String apiKey,
    @Nullable Locale locale
)

Initializes Places for the given application context with the provided API key and Locale.

static void
initializeWithNewPlacesApiEnabled(
    Context applicationContext,
    String apiKey
)

Initializes Places for the given application context with the given API key which has the Places API (New) enabled in the Google Cloud Console.

static void
initializeWithNewPlacesApiEnabled(
    Context applicationContext,
    String apiKey,
    @Nullable Locale locale
)

Initializes Places for the given application context with the given API key which has the Places API (New) enabled in the Google Cloud Console.

synchronized static boolean

Returns whether or not Places has been initialized.

static void

Sets the PlacesAppCheckTokenProvider.

Public methods

createClient

synchronized public static PlacesClient createClient(Context context)

Gets an instance of PlacesClient for a given Context.

Call initialize or initialize before calling this method.

Throws
java.lang.IllegalStateException

if Places hasn't been initialized first (for more info, see initialize or initialize).

deinitialize

synchronized public static void deinitialize()

Deinitializes Places.

This puts Places into its uninitialized state.

Note: this does not need to be called in order to change the API key; to do so, simply call initialize or initialize again.

initialize

public static void initialize(Context applicationContext, String apiKey)

Initializes Places for the given application context with the given API key.

All Places API responses are localized using the device's locale. This method should only be called once prior to using the Places API. You may call this method again to update the API key used; if so, all widgets and instances of PlacesClient will now use this new key.

Parameters
Context applicationContext

The application context in which the Places API will be used in.

String apiKey

The Places API key.

Throws
java.lang.IllegalArgumentException

If the apiKey is empty.

initialize

public static void initialize(
    Context applicationContext,
    String apiKey,
    @Nullable Locale locale
)

Initializes Places for the given application context with the provided API key and Locale.

This method should only be called once prior to using the Places API. You may call this method again to update the API key and locale used; if you do so, all widgets and instances of PlacesClient will now use these new values.

If using this method to initialize within an app which is published as an app bundle, please see documentation to ensure that required resources are available at runtime.

Parameters
Context applicationContext

The application context in which the Places API will be used in.

String apiKey

The Places API key.

@Nullable Locale locale

The locale in which Places API responses will be localized. If null, the device locale at the point of request is used.

Throws
java.lang.IllegalArgumentException

If the apiKey is empty.

initializeWithNewPlacesApiEnabled

public static void initializeWithNewPlacesApiEnabled(
    Context applicationContext,
    String apiKey
)

Initializes Places for the given application context with the given API key which has the Places API (New) enabled in the Google Cloud Console.

All Places API responses are localized using the device's locale. This method should only be called once prior to using the Places API. You may call this method again to update the API key used; if so, all widgets and instances of PlacesClient will now use this new key.

Parameters
Context applicationContext

The application context in which the Places API will be used in.

String apiKey

The Places API key which has the Places API (New) enabled in the Google Cloud Console.

Throws
java.lang.IllegalArgumentException

If the apiKey is empty.

initializeWithNewPlacesApiEnabled

public static void initializeWithNewPlacesApiEnabled(
    Context applicationContext,
    String apiKey,
    @Nullable Locale locale
)

Initializes Places for the given application context with the given API key which has the Places API (New) enabled in the Google Cloud Console.

This method should only be called once prior to using the Places API. You may call this method again to update the API key and locale used; if you do so, all widgets and instances of PlacesClient will now use these new values.

If using this method to initialize within an app which is published as an app bundle, please see documentation to ensure that required resources are available at runtime.

Parameters
Context applicationContext

The application context in which the Places API will be used in.

String apiKey

The Places API key which has the Places API (New) enabled in the Google Cloud Console.

@Nullable Locale locale

The locale in which Places API responses will be localized. If null, the device locale at the point of request is used.

Throws
java.lang.IllegalArgumentException

If the apiKey is empty.

isInitialized

synchronized public static boolean isInitialized()

Returns whether or not Places has been initialized.

setPlacesAppCheckTokenProvider

public static void setPlacesAppCheckTokenProvider(
    PlacesAppCheckTokenProvider appCheckTokenProvider
)

Sets the PlacesAppCheckTokenProvider.