Places

public final class Places


Entry point for the Places API.

Summary

Public methods

static void
addInternalUsageAttributionId(String internalUsageAttributionId)

Adds a usage attribution ID to the initializer, which helps Google understand which libraries and samples are helpful to developers, such as usage of a marker clustering library.

synchronized static PlacesClient

Gets an instance of PlacesClient for a given Context.

synchronized static void

Deinitializes Places.

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

addInternalUsageAttributionId

public static void addInternalUsageAttributionId(String internalUsageAttributionId)

Adds a usage attribution ID to the initializer, which helps Google understand which libraries and samples are helpful to developers, such as usage of a marker clustering library. To opt out of sending the usage attribution ID, it's safe to delete this function call or replace the value with an empty string.

createClient

synchronized public static PlacesClient createClient(Context context)

Gets an instance of PlacesClient for a given Context.

Call initializeWithNewPlacesApiEnabled or initializeWithNewPlacesApiEnabled before calling this method.

Throws
java.lang.IllegalStateException

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

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 initializeWithNewPlacesApiEnabled or initializeWithNewPlacesApiEnabled again.

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 before using the Places API. You can call this method again to update the API key used; if so, all widgets and instances of PlacesClient will now use this new key.

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.

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 before using the Places API. You can 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.