Now, I’m going to quickly explain how to get the Google Maps API Key that goes in your layout file displaying the map. To make this easier for you later on, you will need to get two Maps API Keys – one for debugging your app and one for publishing.
There are two main steps.
First, get the MD5 fingerprint of the certificate (aka key/keystore) that you will use to sign your application. To get the MD5 fingerprint, you will need to use a Java utility called Keytool. Navigate your Command Prompt (Windows 7) to where your Java files are located. Mine is located at C:\Program Files\Java\jre6\bin and C:\Program Files\Java\jdk1.6.0_24\bin. You can use either as long as they have the keytool.exe program in that folder. Optionally: You can add Keytool to your Path.
Now, in the Command Prompt enter the following information (the red text must be changed to values specific for your project):
keytool -list -alias alias_name -keystore C:\Users\Dan\Programming\Android\Keystore\myks.ks
Or, if you are using the default debug.keystore enter the following information (Windows 7 & Vista):
keytool -list -alias androiddebugkey -keystore C:\Users\Dan\.android\debug.keystore -storepass android -keypass android
Now you should have your Certificate Fingerprint (MD5). You can move on to the second step.
Tips for finding where your keystore/certificate is:
- In Eclipse, click on Window->Preferences->Android->Build, and there will be a section called Default Debug Keystore. This gives you the location of your debug.keystore that Eclipse uses to sign your app every time you quickly test it in the emulator or phone.
- Look in your Explorer (Windows) starting from your Eclipse workspace for a folder called Keystore, or for a file ending with .ks. That will be your keystore used for publishing.
- If this is your first time creating an app, then in Eclipse you can right-click on your project name, click Export->Export Android Application->Choose your project’s name->Create new keystore. Copy the location that you save the keystore to. Then, finish the steps in the wizard by creating an alias and another password with a validity length of over 25 years.
Second, go to http://code.google.com/android/maps-api-signup.html, make sure you are logged in, read the Terms of Service, input your MD5 Certificate Fingerprint, then Generate API Key!
After you successfully complete that, copy&paste your Android Maps API Key to your MapView.
In order to display the maps, here are a few things to remember:
The certificate you use to get the API key must be the same you use to sign the app.
- If you are in testing/debugging mode in Eclipse, it automatically signs the app with the default debug.keystore. And if you didn’t use that same default debug.keystore then the map will not show up on your phone.
- If you want to share your map app with others, then you can not use the debug.keystore, as its certificate only lasts a month. When you export your project in Eclipse it always asks if you want to make a new keystore or use an existing one. Use the same one you used to create the API key.