Android Google MapView Tutorial — Done Right!

For a total newbie to the world of Android it would take a while to get this tutorial working. There are too many quirks, the example on the Documentation site did not work properly….so I’m publishing this in case someone comes across the need for a working version of it. Keep in mind that almost all of this code is from Google. Its just purified, corrected and presented in a more understandable manner.

NOTE: I’m a MS Windows based developer, hence the “windows” references (and lack of Mac/Linux stuff in here). However, the code should run no matter where you are developing.

Easy way to get started is to get the Eclipse Java EE IDE for Web Developers, install the Android SDK, get the latest versions of all the frameworks, the Google Maps Add-On, etc and then start learning.
Here’s where you can do that in Eclipse after installing the SDK:
“Window>Android SDK and AVD Manager” on the Menu.
Then you can install the available stuff that you need.

Android SDK & AVD Manager

Android SDK & AVD Manager


To allow you to show maps on your application, Google Maps API needs to identify you and your application (even if you are simply developing). For this you need the API Key for the Android platform.
You can get this by creating an md5 checksum of the debug certificate for you map application (in this case the tutorial).
Find your debug.keystore at
* Windows Vista: C:\Users\<user>\.android\debug.keystore
* Windows XP: C:\Documents and Settings\<user>\.android\debug.keystore
Then use the Keytool (found at C:\Program Files\Java\jdk1.6.0_20\bin) and get the md5 checksum by executing this:
keytool -list -alias androiddebugkey -keystore “C:\Documents and Settings\<user>\.android\debug.keystore” -storepass android -keypass android
Don’t forget the quotes around the path when in Windows!
That should get you the md5 checksum that you can plug into this site and get your Google Maps API Key for Android!


Start a new “Android Project”

New Android Project

New Android Project

Make sure you select the relevant version of Google APIs (in case there’s a newer version by the time you are working on this).
Add a new class called “HelloItemizedOverlay”. You can do that by going to HelloGoogleeMaps2>src>com.example.HelloGoogleMaps2, doing a right click and choosing New>Class.

Adding the HelloItemizedOverlay Class

Adding the HelloItemizedOverlay Class

Follow the above image to choose your options. Then click Finish.
Your project’s Package Explorer should look something like this on Eclipse (my project was called HelloGoogleMaps, yours should be called HelloGoogleMaps2):

Eclipse Package Explorer

Eclipse Package Explorer

Then put these contents into the appropriate files:


<?xml version="1.0" encoding="utf-8"?>
 <string name="hello">Hello World, HelloGoogleMaps!</string>
 <string name="app_name">Hello,GoogleMaps</string>
 <string name="mapskey">YOUR API KEY</string>


<?xml version="1.0" encoding="utf-8"?>
 android:apiKey="YOUR API KEY"


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
 <application android:icon="@drawable/icon" android:label="@string/app_name">
 <activity android:name=".HelloGoogleMaps2" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar">
 <action android:name="android.intent.action.MAIN" />
 <category android:name="android.intent.category.LAUNCHER" />
 <uses-library android:name="" />
 <uses-permission android:name="android.permission.INTERNET" />

package com.example.HelloGoogleMaps2;
import java.util.List;
import android.os.Bundle;

public class HelloGoogleMaps extends MapActivity
 public void onCreate(Bundle savedInstanceState)

 MapView mapView = (MapView) findViewById(;

 List<Overlay> mapOverlays = mapView.getOverlays();
 Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
 HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable,this);
 GeoPoint point = new GeoPoint(30443769,-91158458);
 OverlayItem overlayitem = new OverlayItem(point, "Laissez les bon temps rouler!", "I'm in Louisiana!");

 GeoPoint point2 = new GeoPoint(17385812,78480667);
 OverlayItem overlayitem2 = new OverlayItem(point2, "Namashkaar!", "I'm in Hyderabad, India!");


 protected boolean isRouteDisplayed()
 return false;

package com.example.HelloGoogleMaps2;
import java.util.ArrayList;
import android.content.Context;

public class HelloItemizedOverlay extends ItemizedOverlay<OverlayItem>
 private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
 private Context mContext;

 public HelloItemizedOverlay(Drawable defaultMarker, Context context)
 mContext = context;

 public void addOverlay(OverlayItem overlay)
 protected OverlayItem createItem(int i)
 return mOverlays.get(i);
 public int size()
 return mOverlays.size();
 protected boolean onTap(int index)
 OverlayItem item = mOverlays.get(index);
 AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
 return true;

STEP 4) RUN!!!

If you do not already have the AVD (Android Virtual Device) for the Google Maps Application, create it by going to “Window>Android SDK and AVD Manager” and selecting Virtual Devices on the left hand side.

Create Google Maps AVD

Create Google Maps AVD

Now that all the code is in place, you can run the application:
Right click on the project and choose Run As Android Application

Run Application

Run Application

This is what you should see (provided all the code was entered error free and the API Keys were entered properly):

Overview Result

Overview Result

On Zooming In and clicking on the Placemarkers, we can see the following!

This should be the end result. If you have any questions regarding the code, let me know!

About these ads

109 Responses to Android Google MapView Tutorial — Done Right!

  1. Thanks for ur information :)

  2. rdpatter says:

    wow it’s strange that with Google Maps API being one of the advantages of Android over iPhone that they would screw this up. You cleared it up very well. Thanks.

    • I think Google Maps API is pretty robust. The example that was provided (at least at the time I was working on it) was not rightly done and was frustrating to me as a beginner. That’s the reason I had put this post out.

  3. sathwik says:

    wow.. great job…… ur tutorial helped me a lot….. thankyou..

  4. Arthur says:

    Thanks, couldn’t get the google tutorial to work

  5. Anna-Karin Vesterberg says:

    Thanks so much!
    Cleared that last little piece missing from the tut on the dev site.

  6. Bachi says:

    Thanks so much, your simplified example saved me from chewing for too long on that Google tutorial!

  7. Erik says:

    Thanks for this. I got it working with the points, however the map of the world isn’t showing up (though the points show up where they should be and are working). Any ideas?

    • Not sure exactly what might be causing that in your code, but let me take a shot: Make sure to check your main.xml is done right. Make sure to put YOUR Google maps api key in there. If that does not fix your problem, then take a look at the AndroidManifest.xml and make sure that the permissions and proper libraries are added in.
      Hope this helps!

  8. Erik says:

    Thanks for such a fast reply. I checked both and they’re consistent with your working copy. I’m using the Google API 2.1-update1 API Level 7 version avd. Not sure if that affects it at all. I’ve tried it on there and using Level 8. Definitely a strange issue, as it knows the location of the objects, only the google map isn’t coming through.

    • That certainly is odd. This was dev on 2.1 v8. The map tiles aren’t showing up for your app. That makes me think that either the map key/keystore is messed up. Else, make sure there are no typo-s in the xml files (easy to make, tough to spot!). Also make sure you are giving it time to load…tiles take some sometimes in virtual environment.

  9. Jamen says:

    Hey Thank you for your tutorial , its certainly much more straight forward than the one shown in the actual site. However I do have a problem running both tutorials in which I end up with the same problem where the console says ” Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY . Have you encountered this problem before ? Thanks alot for your tutorial anyway !

    • Jamen says:

      Ok , I just found out the root where this issue might have arose from.
      This was because I using the AVD of the Target Name – Android-2.1-update1 .
      Since the HelloGoogleMap project was created from a Build Target setting – GoogleAPIs – (Platform)2.1 -update1 , I should use the AVD with the same Target Name as well. And it did work :D Took me a while to figure it out … Bummer

      Then I usually encounter a problem in the AVD where it says some device is not responding or busy whenever i run an application. Is it normal for AVD to display that ? Isn’t it a virtual machine ? Why is it that it will lag ?

      • Glad u figured that out. I could not replicate it on my m/c. Not sure why there’s a lag, but from what I’ve seen, usually VDs are slower to boot up every time we’re debugging. Also depends on the hardware u’re running it on. The first few times, it took me abt. 4-5 minutes on my laptop, but was quick after that (if no changes were made)

  10. James Mensah says:

    Do you know of any good Android examples of how to display or get your current GPS location.

    I can’t seem to find a go example that works.


    : )

  11. foo says:

    Small mistake:

    it says in the code
    public class HelloGoogleMaps extends MapActivity

    but it should be
    public class HelloGoogleMaps2 extends MapActivity

  12. aji says:

    may i ask a question?
    i have once generate MD5 checksum long time ago but i forget where i keep it.
    i generate it once again as you suggest above, and get this error: keytool error: java.lang.runtimeexception: usage error, and is not a legal command.

    is this checksum may be generated only once? or what did i do wrong? please help

  13. Eric says:

    Hello, I really like this Tutorial. It is very helpful. But I wanted to ask if you maybe have an example how I can get the Geopoint from a tap. Or also place an overlay item at this position.

    So you should just see a plain map and if the user taps or dubble taps it should show a marker. I am searching for days now for an example but every example which seems to be promising just shows how to identify the list item with a tap. I hope you can help me or at least give me a link to an tutorial

  14. ragav says:


    This is Rgav , i follow ur tutorial it’s very useful me , ang getting output ….also


  15. Ryan says:


    The tutorial is really good and I got everything to work as is. However if I add in a point of my own it refuses to read it in and displays only the 2 outlined here. Any thoughts as to why this happens?


  16. MH says:

    Thanks for the great details on this. I noticed that once the onTap text is displayed, I cannot get back to the map and tap another point. Any idea what might be the problem or how to do this?

    Thanks for any help

  17. Pete says:

    Thanks! Spent hours trying to figure out why I couldn’t get the google tutorial to work. You have provided a nice, clean example that actually worked after following your steps. All I need to do no is go back through and find out why none of the others didn’t and what makes this tick.


  18. anzony says:

    Thanks a lot for your tutorial !!! Merci bcp!

  19. Parag Bhagwat says:

    Thank you for your outstanding tutorial.
    I followed all the steps but do not see the maps. The android icon and the overlay items are displayed.
    I have checked the API key and seems to be correct.
    Can you suggest what else could be the issue?

    Thank you.

    • Thanks for the compliment Parag. The post came about because I was frustrated that Google’s tutorial was incorrectly done.
      From what you said in your post, if map tiles are not visible, it could be one of two things
      1) Check your maps key
      2) make sure your app has the proper settings to access the internet.

      • Parag Bhagwat says:

        I appreciate your prompt reply.
        How do I check that the map key is correct ?
        I can access web sites so I think it is connected to internet. I do see small squares with the android icon on the top. Does loading of map take a long time ? i have waited for more than 5 minutes.

      • Nick White says:

        I was having the same problem and for me it was the key. I found a great keytool plug-in for Eclipse the let you view your M5 fingerprint to use to get your key. Just search Eclipse keytool plug-in. Hope this helps.

  20. Parag Bhagwat says:

    This is the error seen in the error log

    “No command output when running: ‘am start -n com.example.HelloGoogleMaps2/com.example.HelloGoogleMaps2.HelloGoogleMaps2 -a android.intent.action.MAIN -c android.intent.category.LAUNCHER’ on device emulator-5554″

    What does it mean ? Could this be the reason for maps not being displayed ?

    • I’m not sure what the exact problem might be in your case. It could be an issue in the AndroidManifest file. I’ve seen the error when the main activity is missing. If nothing else works, I suggest you create the project from scratch. Make sure Eclipse is configured properly and the right Android version’s Virtual Device is targeted in your project. I’ve seen people having these sorts of issues when they mix up the AVD version.

  21. Nick White says:

    Thank You!!!

  22. Nick White says:

    Code Magician,

    Like I said in my other post thanks for the tutorial.

    I had no problems getting it to work when it was the only activity, but when I tried to add other activities ( A home screen with a button linking to it) it would not work. If I set it back with the “main” and “launcher” intents it works.

    Any ideas what going wrong? Thought I’d post it kind of general just in case. If you need code and errors I can post them also.

    Thanks so much!

    • Nick White says:

      Yea! I got it to work. Some how I moved the other activitys up into the first activity. If that makes scense.

      You should do some more tutoruals, like a list view with headers :) The ones I’ve found were hard to follow compared to yours.

      One last, Thank You.

      • Thanks for posting the solution to the issue you were having! Sorry, didn’t get to your question in time. I will be posting more articles on android and webOS…just have to eke the time out of the week to get it done ;-)

  23. Vinni says:

    How can you now draw a line between those 2 markers????


  24. Pingback: A Map with the Wrong Direction « reinermatthew

  25. Manas says:

    hi, I cant stop myself without thanking u.Really u relieved me after 3 weeks of frustration .
    this is the best tut for gmap.
    Thank u so much.

  26. Manas says:

    hi, can u please send me some more tute on gps and googlemap or some e-book if u have.

  27. bignner says:

    hello experts!!!
    i am facing same problem map don displayed in emulator though all the setting for the avd is rite and all the file in the project is rite. no error displayed in the consle
    only white with small square are seen

  28. Ziku says:

    Thank you for copy pasting the tutorial from following android developer site, without any explanation and guidelines.

    • If you read the post, you will see that I did say this a copy….a WORKING copy….BIG difference. If the original site was changed so that the code works..then awesome….this just a copy.

      Cheers mate!

  29. Julian Fletcher says:

    Brilliant tutorial, absolutely vital in helping me to get the hellogooglemaps application to work properly! – Google Android tutorial writers please take note! :)

  30. Finally! Great piece – thanks!

  31. fsiegel says:

    Excellent tutorial! Really got me ‘over the hurdle’ and on my ay. I do have one request. Has anyone been able to add a label to the individual markers?

  32. karthik says:

    hello sir!

    I tried this code but I m getting only a shadow grid in the background and i couldnt get the map pls help me I m in the mid of my project Pls Pls

    • McMagic says:

      If you are only getting the grid, you need to go back and check the registration of your API key with google: you need to have a valid api key declared for your mapview object inorder for map graphics to load.

  33. McMagic says:

    Just wanted to give you a big thanks — spend hours trying to figure out what was wrong with the documentation’s tutorial. Thanks again for taking the time to put this up — it really helped!

  34. mokarenlam says:

    thank you so much for putting this together. this helped tremendously as i spent a lot of time on the original android tutorial which was less than helpful!

  35. Uldis says:


    Question – if I need to show different items then all need to have a different Overlay because of default drawable in constructor?

    best regards ,

  36. Cameron says:

    Thank you so much for making this. The Google tutorial left out a few important steps to make this work. If you could add a little more info on what each command is doing and why, that would make this tutorial a little better. But, it was great and helped me with the map view.

  37. Good job man. Thanks.

  38. Mike says:


    At step 2) i run the keytool.exe it opens but the window closes after a few secunds and i can’t run the comands…
    Any idea what cloud be wrong?


    • It is a command line tool. Are you double clicking on it or running it from your command line? You aren’t supposed to open the tool…open up cmd.exe (assuming Windows) and then follow instructions.

      • Mike says:

        i’m using win7 so i have to do it in cmd.exe?


      • Yes…and make sure that when you find cmd.exe, right click on it and choose “Run as administrator” option.

      • Mike says:

        I done what you said but when i insert the command it returs
        “Illegal option: and
        keytool -list [OPTION]..”

        i have that line: “C:\Programas\Java\jdk1.7.0\bin>keytool -list -alias androiddebugkey -keystore “C:\Documents and Settings\Mike\.android\debug.keystore” -storepass android -keypass android”

        What am i doing wrohg?

  39. Thx very much.


  40. amv.prasad says:

    how to fix the panning area to the overlayed image in mapview in android

  41. Anthony says:

    Brilliant. Thank you very much.

  42. Ashish says:

    Good work!!! i am having some problem running in android device is not loading only icons are showing with “namaste…”.My device is lg P500 ..i have done exactly the same way as described by you jus changed the google api version to 2.2.

  43. Ashish says:

    i am having some problem running in android device is not loading only icons are showing with “namaste…”.My device is lg P500 ..i have done exactly the same way as described by you jus changed the google api version to 2.2.

    • I think Erik was having the same problem as you…Look at the comments section and see Justin’s reply. I recommend trying that. Tiles not coming up usually is user error, or internet connection not being set up right.

  44. som says:

    Hi I’m working on a map based app. The problem I’m facing is the maps take more time in loading.. any suggestions how to improve the map loading.

  45. ravi says:

    not running send me the complete project at my id-,

  46. ravi says:

    please send me as soon as possible

  47. robocharlie says:

    Thanks for the tutorial – also @developmentality offers this if you want to use different icons:

    Drawable icon = this.getResources().getDrawable(R.drawable.someicon);
    icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());

    You have to manually set the bounds of the icon before you can use it in setMarker().
    If you don’t do this, none of your icons will display.

  48. ravi says:

    how to get the current location exactly on starting of a program with an image showing to that location????????please tell me??

  49. dhruti says:

    Using this code i am not getting google map

  50. Darryl says:

    Job Well Done.

    Much clearer. I was able to run with 1 exception, there is no “icon” but rather “ic_launcher”.

    However this is probably due to changes in Eclipse versions or the Android Add on for Eclipse (I am using Eclipse version:
    Eclipse IDE for Java Developers

    Version: Indigo Service Release 1
    Build id: 20110916-0149
    (c) Copyright Eclipse contributors and others 2000, 2011. All rights reserved.

    The “New project” startup screens are also slightly different in this Eclipse version, but the requested info is still the same.

    Also a big problem I had was a corrupt AVD. I hade all the correct code but got the most obsure errors you’ve ever seen (a literal WTF error was thrown in LogCat). If you’re seeng an odd emulator display or it’s taking forever to load, delete and remake your AVD. Wasted 1/2 day because of this problem.

  51. kheang06 says:

    Wow….it work fine..thank you for your tutorial…:))

  52. diogofbp says:

    I cant see icons on google map.. I drag an image to res-> drawable-hdpi drawable-ldpi and drawable-mdpi

  53. alex says:

    Great tutorial! Puts the crappy Android Tutorials to shame!

  54. momo says:

    how to put multiple icons on map with looping so we don’t have to call the object every time we put new icon?

    ex :
    GeoPoint point = new GeoPoint(30443769,-91158458);
    OverlayItem overlayitem = new OverlayItem(point, “Laissez les bon temps rouler!”, “I’m in Louisiana!”);

    GeoPoint point2 = new GeoPoint(17385812,78480667);
    OverlayItem overlayitem2 = new OverlayItem(point2, “Namashkaar!”, “I’m in Hyderabad, India!”);

    itemizedoverlay.addOverlay(overlayitem); —-> you have to state this as many icon we have
    itemizedoverlay.addOverlay(overlayitem2); —-> how to do these with looping?


  55. chud says:

    Thank You Markk k k k k
    ขอบพระคุณครับ ช่วยผมไว้ได้มากจริง ๆ ฮะ ><"

  56. mangs says:

    use the Keytool (found at C:\Program Files\Java\jdk1.6.0_20\bin) .. this worked for me!!! Great article !!!thnx!!!

  57. Dexter says:

    Great tutorial, just could it be done with a custom View instead of just a drawable?

    I would like to display a “popup” on the map, which would have a background picture (always the same), and a custom square picture over it, and some text.
    For only 2 pictures I could dynamically create a Layer drawable; however I need a Text view too, so I would like a custom View to display on the map (I have an XML for that view with elements ImageView (id: overlay_picture) and TextView (id: overlay_text), with root id “overlay_layout” and it has a background). So how would I accomplish that?
    I saw NOTHING about views neither in OverlayItem, nor in ItemizedOverlay, nor in Overlay.

    Does anyone have an idea?

  58. Andrew says:


    This is great, but I’m trying to do something slightly different.
    1) How would you give each point a different icon? And,
    2) the popup with a title and description is perfect. But can you add a dismiss button and an action button to that popup?


  59. Tumza! says:

    guys im working on android project looking for any code to capture an image using the camera and uploading it to the database …
    if any of you guys have it please e mail it to me as a folder to

  60. Alec Lajoie says:

    Could you extend this tutorial to show a custom dialog on the overlay that uses a LayoutInflater to get an XML that has linkable text? Please and thank you.

  61. Shakeel (android Developer) says:

    Please reply to the following post:———————-It is urgent;————-

  62. rams says:

    ya.. thanks for your tutorial.this is very would explain entire project in simple ways.
    thanks…Rocking tutorial…

  63. Allan K. J. says:

    Thanks Code Magician – this tutorial also saved me from another long night.

    To those who still only sees a grey grid you might need to force keytool to return an MD5 checksum (and not SHA1) by using the -v option:

    keytool -v -list -alias androiddebugkey -keystore “C:\Users\\.android\debug.keystore” -storepass android -keypass android

    Allan K. J.

  64. Kalpesh Sangani says:

    Thank you Very much… Its very useful to me. Great tutorial. Thanks again.

  65. Hella says:

    that is a very nice tutorial thank you..!!

    for me the map is not getting loaded because I am connected through proxy…

    I have defined the proxy settings on the emulator and able to access the internet through browser…

    but My application is not connecting through proxy…

    It says “could not connect to the Connection factory client”

    Could you please help me with this problem

  66. Daniel McMahon says:

    Thanks very much sir, as a few have already mentioned this is the only tutorial that worked for me.

  67. niki says:

    I did EXACTLY according to your instructions. but i am gettin “forced close” when i debug my program, it shows me following errors:
    1)WARNING: Application does not specify an API level requirement!
    2)Device API version is 10 (Android 2.3.4)
    3)Launch error: Failed to connect to remote VM. Connection timed out.

    i have made my app by selecting “Google API” platform “2.3.3” in API “10” and
    it is showing the status “installed” for the following names
    1) SDK platform
    2) Samples for SDK
    3) Google APIs
    for the rest it is showing “uninstalled”
    can u please help me out….my project will remain pending without working on this.

  68. Dan Moore says:

    Note that if you use the jdk7/jdk1.7 keytool, it gives you SHA-1, which is not what you want. I have both jdk6/1.6 and jdk7/1.7 installed, so I just used the jdk1.6 keytool.

    There may be a command line option for the 1.7 keytool to have it output md5, but nothing was obvious to me.

  69. kunal says:

    Unfortunately It isn’t working for me can you elaborate more. I followed all steps shown above and I found a lot of errors in code. Couldn’t fig. out my mistack.

  70. Fred says:

    Very precise tutorial ,Excellent work!

  71. April says:

    may i know what the problem when the google map did not show the surrounding area ?

  72. gargoor says:

    thanks alot man , am a newbie though but following the guide step by step which isn’t bad so far, i wonder if i want to send the data via a gps bluetooth device (else then the phone) what should i add on this app ??

  73. kanna says:

    Nice work..but i didn’t get the map why..?please anyone give me the suggestion..

  74. Tony says:

    Can you please suggest how to get the current location here. I used the code :
    GeoPoint point = new GeoPoint(
    (int) (location.getLatitude() * 1E6),
    (int) (location.getLongitude() * 1E6));
    OverlayItem overlayitem = new OverlayItem(point,””,”” );

    But, Then the app crushes automatically.

  75. gleonio says:

    Thank you for this MapView tutorial! I compiled a list of top resources for adding a MapView to a mobile application. I included your post. Check it out/ feel free to share. Hope other developers find it useful too. :)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: