Getting Android emulator working with Google Maps API Key
I was trying to get an Android app that uses Google Maps API to display a MapView running on the emulator. It took quite a bit of hair pulling to finally get it working.
First, I tried using a self-signed keystore instead of the the debug.keystore provided through the Android SDK. I created my keystore using keytool -genkey from JDK. Then I switch the app from using the default, debug.keystore, to my-new-self-signed.keystore. Using keytool -list, I got the MD5 of the certificate that is needed to obtain a Google Map API key. Then the API key was put into the MapView android:apikey attribute. When I brought up the app in the emulator, I got a blank map grid screen. The reason I wanted to use the self-signed keystore instead of the debug keystore is so I don't have to obtain a new Map API key and change the code to reflect this upon releasing the app.
So, I decided to go with the debug.keystore and that worked fine. Here is what I had to do.
-
$ keytool -list -alias androiddebugkey -keystore <path_to_debug_keystore>.keystore -storepass android -keypass android
- Copy that MD5 and goto http://code.google.com/android/maps-api-signup.html
- Signup for an API key
- In my xml file that has the views for the activity, add
<com.google.android.maps.MapView android:layout_width="fill_parent" android:layout_height="fill_parent" android:enabled="true" android:clickable="true" android:apiKey="example_Maps_ApiKey_String" />
- In the Manifest.xml file, add the permissions needed
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission> - In the Manifest.xml file, add the maps library
<uses-library android:name="com.google.android.maps" />
within the application tag - The entire Manifest.xml looks like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.informationideas.mapapp"
android:versionCode="1"
android:versionName="1.0.0">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<uses-library android:name="com.google.android.maps" />
<activity android:name=".ShowDesktop"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest> - The default activity file should look like this
package com.informationideas.mapapp;
import android.os.Bundle;
import com.google.android.maps.MapActivity;public class ShowDesktop extends MapActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
Now off to building cool things with the map!
May 16th, 2012 - 06:49
I am getting error, when emulator launches, Unfortunately, Google maps has stooped. Any idea??
March 23rd, 2012 - 12:33
Hi…………i have the same problem of showing only Gray Grid. Each and Every thing is fine and no error in any file of code and also internet working in Emulator and also permissions for internet access are added…………..but not working.
Debug API is used…..What the problem may be?
November 25th, 2011 - 04:41
Thanks! It works like a charm.
November 16th, 2011 - 22:56
Thank You so much. This tutorial is very useful for newbie like me
July 14th, 2010 - 00:27
hi .. thanks alot ..
April 28th, 2010 - 03:31
Thax…It helps a lot..Really gr8
March 11th, 2010 - 22:45
I tried to use Google map API. But its giving error on following lines.
1) when i import this package — (import com.google.android.maps.MapView) it give error and ask to make a class MapView in com.google. android.maps
2) When i extend MapViewActivity in class it gives error In androidmaifest.xml that (com.gmap.GoogleMap does not extend android.app.Activity) near .
Please Help. Your Help will be highly appreciated.
Thanks
July 8th, 2011 - 01:14
do one thing go to projects\properties\android…
over der u choose ur api as
google api not android api …
February 28th, 2010 - 19:12
Hi thanx for the tutorial. i’m learning google map api on Android, and this tutorial really helps..thanx..
November 19th, 2009 - 19:24
how about having your own signed key for generating md5 and not the debug key, i can;t render the map from there
July 7th, 2009 - 21:34
hi fnds . i am very beginner to Android .so please suggest me for developing map based applications .And the very basic things has needed to develop this applications and suggest me some api’s related to this applications pls
June 14th, 2009 - 15:26
Great stuff. However it didnt work until i pasted the keystore file into my workspace!
January 5th, 2012 - 22:08
hi
I still get error ‘couldn’t get connection factory client”
there is nothing on the mapview.
please help!
January 16th, 2009 - 00:49
Thanks a lot
The permissions was the last missing thing in my trial (map view was blank without it…). An i have not found it in other tutorials and examples.
December 20th, 2008 - 02:18
Hi thanx it helped me a lot.
December 1st, 2008 - 10:24
Thanks for this post.. It help me a lot. I was also thinking of this way to use an MD5 Generated for application and not using the Eclipse Debug keystore.. Thanks..
November 23rd, 2008 - 14:33
I have not tried creating the views in .java. I suspect that it would encounter the same issue as the problem was with the cert matching the google maps api key. Did this using the debug key work for you?
November 23rd, 2008 - 12:32
Hi
Have been trying to sort a similar problem but not using XML file that has the views for the activity just in a .java file… Have you tried this?