lundi 31 janvier 2011

Create your first Google Maps application

In this article i will show you  the different steps to follow to create your first Google Maps application.
We will also demonstarte some usefull options that  give your application more flexibility and performance.

Creating the Project
Using Eclipse, create a new Android Project and name it  MapsDemo as  shown in Figure 1

Figure 1
Obtaining a Maps API Key
Before you integrate Google Maps in your Application, you need  to apply for a Free  Google Maps API Key.
To apply for key follow the steps  below.
You can refrence to Google's documentation for more  details.

  • First, find this file (debug.keystore)  and copy it (for simplicity) in c:\\Android(Create a folder named Andrioid under c:\\)
  • Extract the MD5 fingerpoint using the keytool.exe included with your JDK installation.You can find the keytool.exe under "C:\Program Files\Java\<JDK_version_number>\bin" folder.
keytool.exe -list -alias androiddebugkey -keystore "C:\android\debug.keystore" -storepass android -keypass android

Modify the  AndroidManifest.xml
Open The  AndroidManifest.xml file and add the following as a child of the <application> element.

<uses-library android:name="" />

You also need access to the Internet to retreive map tiles,so you must also request teh INTERNET permission.In the manifest file, add teh following as a child of the <manifest> element.

<uses-permission android:name="android.permission.INTERNET" />

The AndroidManifest.xml file :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    <application android:icon="@drawable/icon" android:label="@string/app_name">
    <uses-library android:name="" />
        <activity android:name=".MapsActivity"
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
 <uses-permission android:name="android.permission.INTERNET" />
Dispalying the Map
To display the Google Maps in your Android application, modify the main.xml file located in the res/layout folder. You shall use the <> element to display the Google Maps in your activity. In addition, let's use the <RelativeLayout> element to position the map within the activity:

<?xml version="1.0" encoding="utf-8"?>
N.B : android:apiKey : you have to set Your Maps Key.
In the file, modify the class to extend from the  MapActivity  class, instead of the normal Activity class:


import android.os.Bundle;

public class MapsActivity extends MapActivity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

 protected boolean isRouteDisplayed() {
  // TODO Auto-generated method stub
  return false;

That's it !! Your first Google Maps application looks like following :

Zoom, Sreet Maps ...
There's a very simple zom feature built into MapView class, which you can summon with setBuiltInZoomControls(boolean).Do this at the end of the onCreate() method.

MapView mapView = (MapView) findViewById(;

You can also display the map in Street View, using the streetView(boolean) method.


Aucun commentaire:

Enregistrer un commentaire