Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google maps api key not working v2

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 ?

like image 362
tony9099 Avatar asked Dec 12 '22 17:12

tony9099


1 Answers

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.

like image 51
Marcelo Avatar answered Jan 02 '23 03:01

Marcelo