If you want to use MapViews in your application, you must obtaining a Maps API Key. Details are listed athttp://code.google.com/android/add-ons/google-apis/mapkey.html. But there is also something confused, so my experience is recorded. The following is about how to use MapViews for Debug, not for release which is similar. Some words are copied from google code directly.
Step 1. Getting the MD5 Fingerprint of the SDK Debug Certificate
To generate an MD5 fingerprint of the debug certificate, first locate the debug keystore. If you are using Eclipse/ADT and are unsure where the debug keystore is located, you can selectWindows >Prefs> Android > Build to check the full path, which you can then paste into a file explorer to locate the directory containing the keystore. In my Win7 system, the path isC:\Users\test\.android\debug.keystore.
Then, in command line console, type the command:
$ keytool -list -alias androiddebugkey \-keystore <path_to_debug_keystore>.keystore \-storepass android -keypass android
Note that keytool command comes with the Java SDK. You should find it in the directory likeC:\Program Files\Java\jdk1.6.0_27\bin. If you haven't set the Environment variables you may need to navigate toC:\Program Files\Java\<"your JDK version">\bin or others in the command prompt. See Figure 1.
Figure 1
Now, you can get the MD5 Fingerprint.
Step 2. Registering the Certificate Fingerprint with the Google Maps Service
Load this page in a browser http://code.google.com/android/maps-api-signup.html. See Figure 2.
To register for a Maps API Key, follow these steps:
- If you don't have a Google account, use the link on the page to set one up.
- Read the Android Maps API Terms of Service carefully. If you agree to the terms, indicate so using the checkbox on the screen.
- Paste the MD5 certificate fingerprint of the certificate that you are registering into the appropriate form field.
- Click "Generate API Key"
The server will handle your request, associating the fingerprint with your developer identity and generating a unique Maps API Key, and then will return a results page that gives you your Key string.
Figure 2
Step 3. Adding the Maps API Key to your Application
Once you've registered with the Google Maps service and have obtained a Maps API Key, you must add it to your application's MapView objects, so that the Maps server will allow them to download Maps tiles.
For <MapView>
elements declared in XML layout files, add the Maps API Key as the value of a special attribute —android:apiKey
. For example:
<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"
/>
For MapView objects instantiated directly from code, pass the Maps API Key string as a parameter in the constructor. For example:
mMapView = new MapView(this, "example_Maps_ApiKey_String");
Step 4. Final Steps to Enable MapView Elements
If you've added the Maps API Key to the MapViews in your application, here are the final steps to enable the MapView elements to run properly:
- Make sure that you added a
<uses-library>
element referencing the externalcom.google.android.maps
library. The element must be a child of the<application>
element in the application's manifest. For example:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.package.name">
...
<application android:name="MyApplication" >
<uses-library android:name="com.google.android.maps" />
...
</application>
- Sign your application with the certificate that corresponds to the Maps API Key referenced in your MapView elements.
Enjoy it.