Android with Google Maps v2

 The following description is based on the Android with Google Maps v2 which provides significant improvements to the older API version.

The library provides the class and the MapView class for displaying the map component.

You need to add additional information to your AndroidManifest.xml file to use Google Maps.


The MapFragment class extends the Fragment class and provides the life cycle management and the services for displaying aGoogleMap widget. GoogleMap is the class which shows the map. The MapFragment has the getMap() method to access this class.

the LatLng class can be used to interact with the GoogleView class.


You can create markers on the map via the Marker class. This class can be highly customized.

The following code shows an example.

On the GoogleMap you can register a listener for the markers in your map via thesetOnMarkerClickListener(OnMarkerClickListener) method. The OnMarkerClickListener class defines theonMarkerClicked(Marker) method which is called if a marker is clicked.

Similar to you also listen to drag events and info window clicks.

Changing GoogleView

The GoogleMap can be highly customized.

The following example code is taken from the official Google webpage.

Android emulator

Ensure you create an Google API based emulator. This emulator can also be used to test Google map and other Google Play Service integration.

Install Google Play services

Download the Google Play services

Open the Android SDK Manager and install ExtrasGoogle Play services

Create an library project for the Google Play Service library

The Android SDK manager downloads the file to sdk/extras/google/google_play_services/libproject/google-play-services_lib .

Import the library from there into Eclipse via the FileImportAndroidExisting Android Code into Workspace menu entry.

Android with Google Maps v2

To use this library define a library dependency in your Android project.

Google Map key

Google console

To use Google Maps you need to create a valid Google Maps API key. The key is free, you can use it with any of your applications that call the Maps API, and it supports an unlimited number of users.

You get this key via the Google APIs Console. . You have to provide your application signature key and the application package name.

This is based on the key with which you sign your Android application during deployment. During development with Eclipse, Eclipse us automatically creates and uses a debug key.

Creating the SHA-1 for your signature key

The Eclipse debug key for signing your application can be found in the userhome/.android/debug.keystore file.

To create the SHA-1 for your debug keystore you use the keytool command from your JDK installation pointing to thedebug.keystore file.

Copy the SHA-1 output, as you need this later.

Register with the Google APIs Console

You have to register in the Google APIs Console that you want to use Google Maps for Android. You can reach this console via the following link: Google APIs Console. Select here the Services entry.

Activate the Google Maps Android API v2.

Create key for your application

You need later to register your application via its package in this console together with the SHA-1 fingerprint of your signature key. For this you select the entry and click on the API Access entry. Afterwards click on the Create new Android key… entry.

Android with Google Maps v

Enter your SHA-1 fingerprint and the package of your application separated by a semicolon. For example you can use package.

Android with Google Maps

The procedure is described in detail in the following link: Getting a Google Maps key.

Create Project

Create a new Android project called with an activity called ShowMapActivity.

Add permissions to the project

Change the manifest file file to the following code by adding permissions to your application.

Get a valid API key for your application and enter this key in the AndroidManifest.xml file.

Adjust layout file

In this example we use the MapFragment. Change your layout file to the following code.


Change your activity to the following.

Run and Test

Run and test your application. You should be able to zoom in and out and send new geo coordinates to your activity via the Emulator.

Android with Google Maps v2.0