Map in Android

Earlier when the first SDK of androd released, google map is a part of SDK. Now, its not coming with SDK, its coming as add-on.

First for for displaying google map for android application, we need Google map API Key. For this, using the keytool in the JDK, we need to create the finger-print.

We will get the keyStore from eclipse. The path is


I can show a a sample command for getting the finger print in windows xp is,

C:\Program Files\Java\jre1.5.0_06\bin>keytool -list -alias androiddebugkey -keystore "C:\Documents and Settings\Acer\.android\debug.keystore" -storepass android -keypass android

Type this command in dos prompt and you will get the finger print. Then using this finger-print, we need to get the map api key from the url

Sign Up

After getting the API key, use this API key to display map. Then at the time of creating Android application, we need to select the target as Google API 4 or whichever version we need. It is importand that you create an AVD with target as Google API level 3 or greater.

Then for displaying map, we need to extend MapActivity.

For displaying the zoomIn comtrols,


For making the map clickable and focusable, do


For animating to a particular point in map use,

MapController mc = mapView.getController;

For making a point to center, use


For setting the zoom level use,


For drawing over map use Overlay or ItemizedOverlay. Here we are discussing about the ItemizedOverlay.

Using this, we can easily put marker in the map.

Create another class called MyItemizedOverlay which extends ItemizedOverlay which overrides two functions createItem() and size().

Then we create an ArrayList of OverlayItem. In addition, we create a function called addItem(), in that we are adding OverlayItem to the list and calling populate().

Now our MyItemizedOverlay class will look like this,

class MyItemizedOverlay extends ItemizedOverlay {

private ArrayList mOverlays = new ArrayList();
Context ctContext;

public MyItemizedOverlay(Drawable defaultMarker, Context context) {
ctContext = context;

public void addItem(OverlayItem overlay) {

protected OverlayItem createItem(int i) {
// TODO Auto-generated method stub
return mOverlays.get(i);

public int size() {
// TODO Auto-generated method stub
return mOverlays.size();

Then, on tapping the marker, to display some information, I will override onTap() function and create a dialog for displaying the details. The onTap() function will look like this.

protected boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
Dialog dialog = new Dialog(context);
return true;


Popular posts from this blog

AlarmManager and Notification in Android

Swipe Action and ViewFlipper in Android