26

I'm having problems with Android Google Places API - auto complete feature. I use the same key that i used for Android Google Maps API (and in the documentation, it is written this is ok). Here is my definition in manifest:

<meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="mykey"/>

But getAutocompletePredictions returns 'PLACES_API_ACCESS_NOT_CONFIGURED' message as status.

Here is my Java code:

GoogleApiClient googleApiClient = new GoogleApiClient.Builder(context)
        .addApi(Places.GEO_DATA_API)
        .addApi(Places.PLACE_DETECTION_API)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .build();
googleApiClient.connect();

LatLngBounds latLngBounds = new LatLngBounds.Builder().
        include(SphericalUtil.computeOffset(latlon, RADIUS, 0)).
        include(SphericalUtil.computeOffset(latlon, RADIUS, 90)).
        include(SphericalUtil.computeOffset(latlon, RADIUS, 180)).
        include(SphericalUtil.computeOffset(latlon, RADIUS, 270)).build();

PendingResult<AutocompletePredictionBuffer> result = Places.GeoDataApi.getAutocompletePredictions(googleApiClient, constraint.toString(), latLngBounds, null);

AutocompletePredictionBuffer autocompletePredictions = result.await(Config.DATA_TIMEOUT, TimeUnit.MILLISECONDS);

Status status = autocompletePredictions.getStatus();
if (status.isSuccess()) {
    Iterator<AutocompletePrediction> iterator = autocompletePredictions.iterator();
    while (iterator.hasNext()) {
        AutocompletePrediction prediction = iterator.next();
        //... do stuff here ...
    }
}
else {
    Log.d(TAG, status.getStatusMessage());
}

autocompletePredictions.release();
googleApiClient.disconnect();

Thanks in advance

enver
  • 337
  • 1
  • 3
  • 10
  • Did you enable Google Places API for Android in developers console ? It is not the same API as maps. And you should also check in credentials that your Public API access is still there. I had this problem yesterday and my key just disappeared – andrei Jul 16 '15 at 09:03
  • Thank you @schopy the same key problem here – enver Jul 16 '15 at 12:43
  • I am having a similar kind of problem, but not exactly the same. http://stackoverflow.com/questions/31640783/geodataapi-getautocompletepredictions-not-working. Anyone, please help. – zookastos Jul 26 '15 at 22:45
  • 1
    Seems that the Google Play Services version of the Places SDK for Android is deprecated as of January 29, 2019. I changed the dependencies to `implementation 'com.google.android.libraries.places:places-compat:1.0.0'`. I have added the API key in manifest file as well. But I am still getting the error `PLACES_API_ACCESS_NOT_CONFIGURED`.Any idea on how to resolve it? – harsh pamnani Mar 01 '19 at 03:11

9 Answers9

51

Enable the Google Places API for Android in developers console and check on the credentials page that your key is still present

andrei
  • 2,934
  • 2
  • 23
  • 36
  • Thanks you so much, I wasted my whole for after this thing. – Genutek Jul 18 '17 at 20:16
  • Now we have to use Places SDK for Android specifically – Faisal Mohammad Sep 23 '18 at 12:12
  • 4
    Nirzon, can you please clarify how to enable Place SDK for Android? When enabling APIs and querying for "Place SDK for Android", Google returns only "Places API", which keeps giving me the PLACES_API_ACCESS_NOT_CONFIGURED 9003 error. Thanks – nibbana Feb 05 '19 at 18:25
26

Step by step Solution that I follows :

enter image description here

Kapil Rajput
  • 11,429
  • 9
  • 50
  • 65
  • 1
    I already did this, the problem is, `PLACES_API_ACCESS_NOT_CONFIGURED`, but the ApiKey is already there! –  May 12 '17 at 16:27
  • Omg... You would think that creating an Android key and adding restrictions for Places and Maps would imply that the keys would work for them... but there are separate enable buttons hidden on a completely different page *smh*. – arao6 Aug 27 '18 at 03:03
1

I think you tried enabling Google Places API for Android

Enable this as well it works . You can found this below Google Places API for Android

Google Places API Web Service
madhu527
  • 4,644
  • 1
  • 28
  • 29
1

Hi Friends I have successfully resolve this issue.I was implementing Auto Complete Goole places in my app. This was provided by Google play services. Now the main issue is that Place SDK for Android is deprecated from Google play services on 29 Jan.Now,A new SDK is released instead of. Place sdk for Android. Now you can use this migration guide to implement place sdk in your project. Link is available here.

Place SDK for Android migration guide.

Also see the step by step guide how to implement AutoComplete in your project .Look here this linkstep by step guide to implement Autocomplete in our app.

Hope this will help you.Thanks.....

Rahul Kushwaha
  • 5,473
  • 3
  • 26
  • 30
1

After a lot of searching and spending a lot of time, I found out that we need to replace From implementation 'com.google.android.gms:play-services-places:15.0.1'

Replace to implementation 'com.google.android.libraries.places:places-compat:1.0.0'

The code demo can be found at following location: https://github.com/googlemaps/android-places-demos

0

googleApiClient.connect(); should be called in the method onMapReady of the interface OnMapReadyCallback.

0

there are two ways to get your Place API working either by Intent or AutocompleteFragment, in the case of intent you can restrict your search to a specific country but the same is not applicable to the AutocompleteFragment yet. below is the code that worked for me:

  <fragment
        android:id="@+id/autocomplete_fragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

activityCode:

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gms.common.api.Status;
import com.google.android.libraries.places.api.Places;
import com.google.android.libraries.places.api.model.Place;
import com.google.android.libraries.places.widget.AutocompleteSupportFragment;
import com.google.android.libraries.places.widget.listener.PlaceSelectionListener;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;

public class AutocompleteFragmentActivity extends AppCompatActivity {
    private String TAG ="FRAGMENT_AUTOCOMPLETE";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_autocomplete_fragment);

        /**
         * Initialize Places. For simplicity, the API key is hard-coded. In a production
         * environment we recommend using a secure mechanism to manage API keys.
         */
        if (!Places.isInitialized()) {
            Places.initialize(getApplicationContext(), "API_KEY");
        }

// Initialize the AutocompleteSupportFragment.
        AutocompleteSupportFragment autocompleteFragment = (AutocompleteSupportFragment)
                getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);

        assert autocompleteFragment != null;
        autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));


        autocompleteFragment.setOnPlaceSelectedListener(placeSelectionListener);

    }
    PlaceSelectionListener placeSelectionListener = new PlaceSelectionListener() {


        @Override
        public void onPlaceSelected(@NonNull Place place) {
            Log.i(TAG, "Place: " + place.getName() + ", " + place.getId());
            Toast.makeText(AutocompleteFragmentActivity.this, place.getName()+", "+ place.getAddress(), Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onError(@NotNull Status status) {
            Log.i(TAG, "An error occurred: " + status);

        }
    };

}

activity class for Intent

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.widget.Toast
import com.google.android.libraries.places.api.Places
import com.google.android.libraries.places.api.model.Place
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
import java.util.*


class AutocompleteActivity : AppCompatActivity() {
    private var AUTOCOMPLETE_REQUEST_CODE = 0
    private var TAG: String = "AUTOCOMPLETE_ACTIVITY"
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_autocomplete)

        if (!Places.isInitialized()){
            Places.initialize(this, "API_KEY")
        }
       // val placesClient = Places.createClient(this)
        val fields = Arrays.asList(Place.Field.ID, Place.Field.NAME,Place.Field.ADDRESS)


        val intent = Autocomplete.IntentBuilder(AutocompleteActivityMode.FULLSCREEN, fields)
            .setCountry("NG")
            .build(this)

        startActivityForResult(intent,AUTOCOMPLETE_REQUEST_CODE)
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == AUTOCOMPLETE_REQUEST_CODE){
            if (resultCode == Activity.RESULT_OK){
                val place = Autocomplete.getPlaceFromIntent(data!!)
                Log.i(TAG,"Place: "+ place.name + ", "+ place.id)
            }
            else if (resultCode == AutocompleteActivity.RESULT_ERROR){
                val status = Autocomplete.getStatusFromIntent(data!!)
                Log.i(TAG, status.statusMessage)
            }
            else if (resultCode == Activity.RESULT_CANCELED){
                Toast.makeText(this@AutocompleteActivity, "You cancelled the operation", Toast.LENGTH_LONG).show()

            }
        }
    }
}

Don't forget to add your dependencies

dependencies {

    implementation 'com.google.android.gms:play-services-places:16.0.0'
    implementation 'com.google.android.libraries.places:places:1.0.0'
}

For this to work you must add both to your gradle file Try this it should work!!! :)

Chidinma Ekenne
  • 121
  • 3
  • 9
0

You can use this version of the places api as the dependency.

implementation 'com.google.android.libraries.places:places-compat:1.1.0'
0

In addition to setting up API key and enabling APIs as noted by others, I had to do the following:

  1. Set up a billing account (I was getting "maximum limit exceeded..." error
  2. Switch to using the Places SDK client library as outlined here: https://developers.google.com/places/android-sdk/client-migration. (Note that I did not choose to use the compatibility library since Google Play Services version of the Places SDK for Android will be turned off on July 29, 2019.)
Pika Supports Ukraine
  • 3,612
  • 10
  • 26
  • 42