To start using Google Maps on your Android application, you need no more than a MapView and some GeoPoint. Nevertheless, in order to show map tiles loaded and drawn on your Android application when debugging (on AVD or phone), you’ll have to obtain a Maps API Key.
The procedure splits in three steps:
- Obtain the debug certificate (official procedure here)
- Sign up for a Maps API (official procedure here)
- Start playing with MapView !
Step one: obtain the debug certificate
Each installed Android SDK have a unique debug certificate. You’ll have to get the MD5 Fingerprint of this certificate in order to pretend a Maps API key.
First, we have to locate the debug.keystore file on the computer and note down its path. This file is generally located at these following paths:
# Linux / MacOS ~/.android/debug.keystore
# Windows C:\Documents and Settings\<user>\.android\debug.keystore
Please note that .android is a hidden directory in both OS.
Then, we must generate the MD5 Fingerprint of our debug keystore. To do so, we will use keytool, a tool bundled with any java JDK. You can find it in the following paths (or similar).
# Linux $JAVA_HOME/bin/keytool # MacOS JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home $JAVA_HOME/bin/keytool
# Windows C:\Program Files\Java\jdk1.6.0_23\bin\keytool.exe
Open a terminal or a dos box and change the working directory to the java bin/ path seen above (the keytool directory). You can now launch the following command:
keytool -list -alias androiddebugkey -keystore "path_to_your_debug.keystore" \ -storepass android -keypass android
Note down the generated MD5 Fingerprint present in the result. It should look like:
01:E9:C8:C0:BF:E3:4C:5F:A3:EE:28:33:BD:10:D3:19
Step two: sign up for a Maps API key
We have now to register the debug certificate with the Android Maps API service.
Connect to the Maps API Signup page and enter your MD5 Fingerprint. (Read and) Accept terms of use and validate the form.
You just obtain the key you need to load map tiles in your Android application. It should look like:
16ahjArI_Z393VYwzeGYJFT62pmG3LuKgZ0jy9w
Step three: start playing with MapView !
To draw a MapView in your application, simply paste the following code snippet in a XML layout. Don’t forget to write your own API key in the android:apiKey property.
<com.google.android.maps.MapView android:id="@+id/MyMapView" android:layout_width="match_parent" android:layout_height="match_parent" android:clickable="true" android:apiKey="16ahjArI_Z393VYwzeGYJFT62pmG3LuKgZ0jy9w" />
You’ll probably need to change the API key for a production one. Instead of putting the API key into the XML layout, prefer define a string value by editing the res/values/strings.xml as following:
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="apikey">16ahjArI_Z393VYwzeGYJFT62pmG3LuKgZ0jy9w</string> </resources>
And replace the android:apiKey value, in a XML layout, by:
android:apiKey="@string/maps_apikey"
I really recommend this site for those who work with eclipse in mac os. Excellent explanation! Keep it up!