Maps Development on Android: Registering a Maps API key

Location based applications are  musts on mobile platforms. Android does not have maps natively but Google Maps team is providing an add-on that comes with Android SDK (at least 1.5). In this post, I’m not going to show you how to pop out maps on your little mobile screen, but underline the application signature details related with Maps API.

First of all in our to show map tiles properly, we need an API key. This is all because you are requesting from Google Data API and have to agree with the terms of service. I’m also sure that quote rules also apply.

Every Android application is signed with a signature of the publisher. While obtaining a key, you must provide the MD5 summary of your signature to Google, and Google activates possible transactions between Maps API and the application your signature signs. In order to complete these actions, you have to

  1. Obtain the MD5 summary of your signature. If you do not have a signature, you can use the default one.
  2. Sign up for an API key directly from Google by providing the hash of your signature.
  3. Use API key with map elements and generate a sample map view.

Obtaining an API key

You will have to use the keytool to obtain information about signatures. If you haven’t created one, Android SDK puts a default one in your ~/.android directory. In this tutorial, I’m going to show you how to register with this default signature. Open a terminal prompt and enter

$ keytool -list -keystore ~/.android/debug.keystore

It’s going to ask you the password of the keystore (debug.keystore). Default is “android”. If you receive a MalformedKeyringException, you are giving the wrong password. If everything works great, it will output a few lines of information including the hash. Please read the summary line and copy the hash.

Certificate fingerprint (MD5): E8:F4:F2:BF:03:F3:3A:3D:F3:52:19:9B:58:20:87:68

After obtaining the summary key, you can jump to the next level — signing up for an API key. Give the hash as input and register. Please note the API key Google has given to you.

Generating Maps on Android

Android SDK comes with two archives. First one is the android.jar which contains the standard platform libraries. And maps.jar which is a library dedicated to generation of maps. In the maps API, you will notice MapView. You can extend MapView to customize and add new features to show a custom map view. Or invoke the existing methods to perform simple operations like panning, zooming and adding overlays to show information on the default map. There are great tutorials about Android’s map view and controller on web, I simply didn’t want to copy-cat the existing. Google’s Hello, MapView is a place to start.

Multiple-Developer Cases

A signature can only be associated with a single API-key. What you are going to do if development is made across a team? You dont need to create different signatures for each developer and register them to use Data API one by one. Register a single signature and obtain a key. Then, distibute the signature among the developers – better add it to your version controlling system.

5 thoughts on “Maps Development on Android: Registering a Maps API key

  1. Thank you for discussing the need of the distribution of signatures. We have been working simultaneously on a single Android application and could not make it work with different signature-api key couples. Just copied the first signature we registered to other machines and redeployed the application. It works like a charm now.

  2. Nick, that’s great. I wanted to point it out that sharing default keystore is going to work. While working on a maps application, I felt into a random feeling that signatures are one per development machine. So, I registered another for my machine. There were no tiles and nothing was working properly. Almost spending one full time to find a work around, I decided to copy my colleague’s keystore. But unfortunately, I again decided to obtain a hash on my own machine and go and register. It didnt work again.

    Finally, I copied the keystore, changed the API key to the original he got with the initial signature and it worked.

  3. Hi, Thanks for the article. Under “Multiple-Developer Cases” you say to “distibute the signature among the developers” in order to use the same dev api key on different machines. I’m not sure how to do this. I tried coping the debug.keystore file to another machine but this did not work. Can you please provide some details?

    Thanks,
    Paul

  4. Wow, that really impressed me! I like your ideas. And the cartoon made it even better! Thanks for sharing your concept! Cheers……….

Leave a comment