13

I want to show place picker so that user can choose location of his/her own choice. But place picker child activity automatically closes after launch. I've check the API key multiple times and other permissions, everything is correct. Here is all the code. Please help!

task_location.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder();
                Intent intent = intentBuilder.build(NewTaskActivity.this);
                // Start the Intent by requesting a result, identified by a request code.
                startActivityForResult(intent, 123);


            } catch (GooglePlayServicesRepairableException e) {
                GooglePlayServicesUtil
                        .getErrorDialog(e.getConnectionStatusCode(), NewTaskActivity.this, 0);
            } catch (GooglePlayServicesNotAvailableException e) {
                Toast.makeText(NewTaskActivity.this, "Google Play Services is not available.",
                        Toast.LENGTH_LONG)
                        .show();
            }
        }
    });

And here is the menifest file.

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    tools:replace="android:icon">

    <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="AIzaSyAjM9hWUXm8vlABqFbM_fJfQgIFli8HP1E"/>
Zeeshan Ahmed
  • 1,179
  • 2
  • 13
  • 30

6 Answers6

27

Please check the logcat of your app for 'PLACES_API_ACCESS_NOT_CONFIGURED' message. If this is the case, enabling the Google Places API for Android in your Google Developer Console for this project should solve your problem.

mkaminski
  • 271
  • 1
  • 2
  • 4
  • 1
    Thanks, Its worked for me after i enable`Google Places API Web Service` API in Google Api developer console – Ninja Jul 06 '17 at 17:15
  • 2
    i am getting same issue i had enable place api already but getting still issue is there any solution? – Mehul Tank Feb 08 '19 at 10:38
10

After A lot of debugging i solved it myself. The problem was package name..Android studio manage package name by itself on project creation. I change the package name in manifest and it was working perfectly fine. but when i get API key from google developers console for place picker, place picker automatically closes without a single character of error.

Then I change the package name by going into -> Module Settings -> Flavors and change the Application ID and it fix the problem.

Zeeshan Ahmed
  • 1,179
  • 2
  • 13
  • 30
2

Make sure that Google Places API is enabled for the API key that you are using in Google API console. For me, I am using the same API key that I use for maps. I just enabled the same key for places api also. That solved my problem. Use this link to access the Google console: https://console.developers.google.com/flows/enableapi?apiid=placesandroid&reusekey=true

Gopi Ande
  • 81
  • 7
1

Solved problem by just changing the API key

You can create a new key from here

Android Dev
  • 1,496
  • 1
  • 13
  • 25
1

Instead of enabling the places API, Enable the places SDK for android. Worked for me. Good Luck :)

1

Enable both places API as well as Places sdk