Obtaining a mapapi Key from Google

The first thing to understand about the map-api key is that you'll need two keys: one for development with the emulator, and another for production (on the device). The reason for this is that the certificate used to obtain the map-api key will differ between development and production (as we discussed in the first part of this chapter).

For example, during development, the ADT plug-in generates the .apk file and deploys it to the emulator. Because the .apk file must be signed with a certificate, the ADT plug-in uses the debug certificate during development. For production deployment, you'll likely use a self-signed certificate to sign your .apk file. The good news is that you can obtain a mapapi key for development and one for production, and swap the keys before exporting the production build.

To obtain a map-api key, you need the certificate that you'll use to sign your application. (Recall that in the development phase, the ADT plug-in uses a debug certificate to sign your application for you prior to deployment onto the emulator.) So you'll get the MD5 fingerprint of your certificate, then you'll enter it on Google's web site to generate an associated mapapi key.

First you must locate your debug certificate, which is generated and maintained by Android. On a Windows XP machine, this is the path to the certificate:

C:\Documents and Settings\<username>\Local Settings\Application Data\ Android\debug.keystore

You can find the exact location using the Eclipse IDE. Go to Window > Preferences > Android > Build. The debug certificate's location will be displayed in the "Default debug keystore" field, as shown in Figure 7-4.

Figure 7-4. The debug certificate's location

To extract the MD5 fingerprint, you can run the keytool with the -list option, as shown in Listing 7-10.

Listing 7-10. Using the Keytool to Obtain the MD5 Fingerprint of the Debug Certificate keytool -list -alias androiddebugkey -keystore "C:\Documents and Settings\sh\ Local Settings\Application Data\Android\ debug.keystore" -storepass android -keypass android

Note that the alias of the debug store is androiddebugkey. Similarly, the keystore password is android and the private-key password is also android. When you run the command in Listing 7-10, the keytool provides the fingerprint (see Figure 7-5).

~ C:\WINDOWS\system32\cmd.exe Q|

C:\Program Files\Jaua\jdkl.6.0_07\bin>keytoo1 —list —alias androiddebugkey —keys tore "C:\Documents and Sett ings\sli\Local Settings\Application Data\Android\debug .keystore" —storepass android -keypass android androiddebugkey, Sep 26, 2008, PriuateKeyEntry,

Certificate fingerprint <MD5>: 57:60:66:6F:63:E6:5F:6B:89:5F:47:3C:D1:12:F8:00 C:\Program Files\Jaua\jdkl.6.0_07\bin>

Figure 7-5. The keytool output for the list option

Now paste your certificate's MD5 fingerprint in the appropriate field on this Google site:


Then click the "Generate API Key" button to get a corresponding map-api key from the Google Maps service. The map-api key is active immediately, so you can start using it to obtain map data from Google. Note that you will need a Google account to obtain a map-api key—when you try to generate the map-api key, you will be prompted to log in to your Google account.

Now let's start playing with maps.

0 0

Post a comment