I was trying to implement the Places API. My code looked like this:
val builder = PlacePicker.IntentBuilder()
startActivityForResult(builder.build(mActivity), PLACE_PICKER_REQUEST)
My maps credentials were correct, but for this call I got
Places API for Android does not seem to be enabled for your app. See https://developers.google.com/places/android/signup for more details.
However, when I tried to enable the "Places API for Android", I got this error.
You do not have sufficient permissions to view this page.
I tried logging out of my accounts, logging in again, incognito mode, Safari & Chrome. Nothing worked so I contacted support, which were extremely fast (thanks guys!)
The reason you are receiving an error when trying to enable the Places
for Android API is that it has been deprecated. Places functionality
for android will now be covered by having the Places API enabled.
I asked about my implementation and got this reply.
The place picker has also been deprecated. You can install the
compatibility library to continue using the Place Picker until the
deprecation period ends on July 29th. More about this can be red here:
https://developers.google.com/places/android-sdk/client-migration#place_picker
The docs I find online now are a bit confusing, what is deprecated and what isn't? Can anyone point me in the right direction for this kind of functionality?
Google Places SDK for Android is Deprecated, so we need to migrate for Places API.
For implementing AutoComplete Place using new Places API.. please follow below steps.
First enable PlacesAPI in developer console, then install Client Library by updating in gradle.
(Note: You can only install either the client library or the
compatibility library, NOT both)
implementation 'com.google.android.libraries.places:places:1.0.0'
Now initialize below code inside Oncreate();
// Add an import statement for the client library.
import com.google.android.libraries.places.api.Places;
// Initialize Places.
Places.initialize(getApplicationContext(), "***YOUR API KEY***");
// Create a new Places client instance.
PlacesClient placesClient = Places.createClient(this);
New PlacesAPI is initialised..
For AutoComplete places use below code (You can use AutoComplete Fragment also)
// Set the fields to specify which types of place data to return.
List<Place.Field> fields = Arrays.asList(Place.Field.ID, Place.Field.NAME);
// Start the autocomplete intent.
Intent intent = new Autocomplete.IntentBuilder(
AutocompleteActivityMode.FULLSCREEN, fields)
.build(this);
startActivityForResult(intent, AUTOCOMPLETE_REQUEST_CODE);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == AUTOCOMPLETE_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
Place place = Autocomplete.getPlaceFromIntent(data);
Log.i(TAG, "Place: " + place.getName() + ", " + place.getId());
} else if (resultCode == AutocompleteActivity.RESULT_ERROR) {
// TODO: Handle the error.
Status status = Autocomplete.getStatusFromIntent(data);
Log.i(TAG, status.getStatusMessage());
} else if (resultCode == RESULT_CANCELED) {
// The user canceled the operation.
}
}
}
- Make sure permissions in manifest
- API key generated.
- Places API is enabled in Dev Console.
REMOVE(if you added)
implementation 'com.google.android.gms:play-services-places:16.0.0'
Required header files
import com.google.android.libraries.places.api.Places;
import com.google.android.libraries.places.api.model.Place;
import com.google.android.libraries.places.api.net.PlacesClient;
import com.google.android.libraries.places.widget.Autocomplete;
import com.google.android.libraries.places.widget.AutocompleteActivity;
import com.google.android.libraries.places.widget.model.AutocompleteActivityMode;
Hope this will help..
Despite Google has provided new API for Places SDK, they are dropping support for Place Picker because of new billing policy, and there are two options how to handle this.
You can implement this logic by your self using new SDK.
Or luckily there is this Ping Place Picker library which mimics
the behavior of old Place Picker.
The Google Play Services version of the Places SDK for Android (in Google Play Services 16.0.0) is deprecated as of January 29, 2019, and will be turned off on July 29, 2019. And if you check under the google API console, it only have the PLACES API and there is nothing like PLACES SDK FOR ANDROID anymore.
Migration guide to new places SDK client library can be found here
Or find custom implementation in my repo => NewGooglePlacesSDK