google maps api key not working v2

18,398

Solution 1

You're generating an ApiKey for the Google Maps V2, but you are using the v1 MapView com.google.android.maps.MapView. On the Android Maps V2 API, the key is placed on the manifest, and you use com.google.android.gms.maps.MapView to show the map, using the Google Play Services Library.

I suggest reading the overview section here to learn how to setup your Project with the Google Play Services Library, and looking at the new API Reference here.

Solution 2

If you are developing google maps api. You need to have two sets of map api key. One map api key that is generated by using your SHA1 fingerprint from your debugging keystore, this map api key is to be used when you are debugging your app in eclipse and running it from there. The other map api key is generated by using your SHA1 fingerprint from official or production keystore, this map api key is used when you will signed or publish your app.

I think you are experiencing mismatch of your keys there since the map api key on the manifest is from debugging keystore and you have signed your app with your official keystore.

Also I think you are developing MapView. It is recommended now to use MapFragments now. I have links here that might help you.

Quick Start Guide: https://docs.google.com/document/d/1dFzZT0C782BxLkDIUEb711rmsbMmYPURFV_2Cdb36so/edit?usp=sharing

Trouble shooting thread if you encounter problems with MapFragment or Google Play Services Library: Unable instantiate android.gms.maps.MapFragment

Also I have answers here in this How to/Error in declaring google-play-services-component that might help you.

Share:
18,398

Related videos on Youtube

tony9099
Author by

tony9099

worst programmer on the entire planet.

Updated on September 14, 2022

Comments

  • tony9099
    tony9099 over 1 year

    I had an android application that utilizes google maps. I have followed the instuctions and made the app working in debug mode using the debug key. I have retrieved my SHA-1 key from the debug.keystore found here.

    c:\Users\myself\.android\debug.keystore

    using

    c:\Program Files\Java\jdk1.7.0_03\bin>keytool -list -v -keystore c:\debug.keystore

    The map was showing fine whenever I used tethered debug by running the app from eclipse on my test phone (which ran android 2.3.6).

    However, after finishing the app, in the published app the map did not show. What was visible were only grey tiles.

    I know this is an issue with the API key.

    So I created a new key, (and an apk with it) used it to generate a new API key from the google's console. I deleted the apk that was generated with the key, as it had the old ApiKey, and pasted the new api key here.

    <com.google.android.maps.MapView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:id="@+id/mymap"
    android:apiKey="my_api_key"
    

    Then I re exported my project but this time used the same key that I had created the step before as they contained the same SHA-1.

    However, still the map does not show and only grey tiles appear. I have entered my SHA-1 key in the api console in the following way.

    18:3E:1D:8C:xx:xx:xx:xx:xx:xx:xx:xx:xx:x:xx:1D:E1:08:32:8E;com.mycompany.mapapp

    I tried to revert back to my debug key, but this time the debug app (running from eclipse) also did not show any maps.

    my questions are the following.

    1. Is this still the correct method to use? Because in the --https://developers.google.com/maps/documentation/android/start#obtaining_an_api_key -- google used different approach using fragments.

    2. What am I missing ?

    3. Is this method deprecated or should work ?

    • Thibault D.
      Thibault D. about 11 years
      Show us your AndroidManifest. I wonder as well about the space in "18:3E:1D:8C:xx:xx:xx:xx:xx:xx:xx:xx:xx:x:xx:1D:E1:08:32:8E; com.mycompany.mapapp", try to remove it.
  • tony9099
    tony9099 about 11 years
    what do you mean by 'mismatch' ? can you elaborate more ? and if possible give an example ?
  • Ariel Magbanua
    Ariel Magbanua about 11 years
    @tony9099 when you run your app straight from eclipse you are basically installing apk signed with your debug.keystore, now since your app is using the map api key generated from SHA1 of your debug.keystore it will work fine. Now if you are publishing the apk you are signing it with your own keystore, maps won't show now because your map api key is from debug.keystore. You have to generate map api key using your the SHA1 fingerprint from your own keystore and use that map api key when you will publish or signed your app.
  • Marcelo
    Marcelo about 11 years
    Only for old applications that still use the V1 ApiKey. You're using a v2 ApiKey, so you have to change your code to the V2 version, including the correct MapView/Markers/Overlays/etc.
  • Ariel Magbanua
    Ariel Magbanua about 11 years
    I updated my answer with additional information and links. I hope that will help you. :)
  • Marcelo
    Marcelo about 11 years
    If you generated a V1 ApiKey using your release keystore, you can still use your old code with that key. Unfortunally there's no way to generate a V1 ApiKey now, so if you don't have an old key you need to update your code
  • wallerjake
    wallerjake over 10 years
    Thanks for the post I forgot about a production / debugging one.