Google PlacePicker Closes Immediately After Launch

老子叫甜甜 提交于 2019-12-01 02:04:56

Just enable Google Places API for Android in your Google Developer Console.

Don't forget to specify your API key at AndroidManifest:

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

I believe that when Google made changes to their API's on 04/20/2015 they modified the places API that the PlacePicker inherently uses. The solution that worked for me is as follows:

  1. Go to your Google Developer Console (https://console.developers.google.com/project)
  2. Navigate to your project if you have made one. If not go here: https://developers.google.com/console/help/
  3. Navigate to "APIs & auth" then to "Credentials" on the left side of the console. I don't have enough rep to post a picture for guidance...
  4. Create a new Key, this appears under Public API access in your Credentials window. You will need your SHA1 Fingerprint to receive the key. Directions that I used are here: How to get the SHA-1 fingerprint certificate in Android Studio for debug mode?
  5. The location that you input your SHA1 Fingerprint should be in this format: (Your Key, 20 Hex values separated by ":");com.yourpackage.yourapp
  6. Copy your API Key that is generated. You will need to add the fingerprint of each developer in the same format above for it to work for other developers.
  7. Add your key to your AndroidManifest.xml

<application ...

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

... </application>
Where the "@string/google_api_key" /> is the key that you just generated. Place it in your strings.xml file as such:
<string name="google_api_key">yourkeyhere</string>
  1. Clean and Rebuild your project. Should be working now. I don't think I left any steps out... Please comment if I have.
thethanh

I have the same issue. I add Google map key

<meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="@string/google_maps_key"/>` in manifest file. 

The Place Picker closes immediately. Then, i also add

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

The Place Picker shows, but when i open map, my app was force close, and log like below.

RuntimeException: The API key can only be specified once. It is recommended that you use the meta-data tag with the name: com.google.android.maps.v2.API_KEY in the <application> element of AndroidManifest.xml
        at com.google.maps.api.android.lib6.d.fb.a(Unknown Source)
        at com.google.maps.api.android.lib6.a.g.a(Unknown Source)
        at com.google.android.gms.maps.internal.CreatorImpl.b(Unknown Source)
        at com.google.android.gms.maps.internal.CreatorImpl.b(Unknown Source)
        at com.google.android.gms.maps.internal.i.onTransact(SourceFile:62)
        at android.os.Binder.transact(Binder.java:364)
        at com.google.android.gms.maps.internal.zzc$zza$zza.zzj(Unknown Source)
        at com.google.android.gms.maps.SupportMapFragment$zzb.zzqs(Unknown Source)
        at com.google.android.gms.maps.SupportMapFragment$zzb.zza(Unknown Source)
        at com.google.android.gms.dynamic.zza.zza(Unknown Source)
        at com.google.android.gms.dynamic.zza.onCreate(Unknown Source)
        at com.google.android.gms.maps.SupportMapFragment.onCreate(Unknown Source)
        at android.support.v4.app.Fragment.performCreate(Fragment.java:1763)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:915)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1136)
        at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
        at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1499)
        at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:456)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5103)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
        at dalvik.system.NativeStart.main(Native Method)

I try to remove

<meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="@string/google_maps_key"/>` 

but keep

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

And It's working well, now, and I don't know why.

replace your meta data tag in the mainfeast .. it works for me ..

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="YOUR ANDROID KEY" />

with

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

good luck

I had the same problems using the Places API. At the end, I figured out that there are different Google Places APIs especially for Android. Consequently, the API-Key that I was using was simply for the non-Android version.

Generate your key using this link: https://developers.google.com/places/android-api/signup

in my case GO to Google COnsole then Enabled API for Android Google Places, then Go to Manifest.xml and put this code under

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

and dont forget to put Google API key

How i fixed this error was when getting an API key (On Google Developers Page) , the location where you enter your package name enter your complete package name. This is available in your android manifest!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!