This quick guide will show you exactly what code you need to put in your Android project. You will also need a Google Maps API Key, later. Tip: Your “Project Build Target” must include Google APIs in order to show the map. To find your current build target in Eclipse, right-click on your project’s name->Properties->Android.

There will be three files to edit. A xml file, java file, and the manifest.

First, in your project’s manifest (AndroidManifest.xml) add the following lines of code that are bolded and the red code must be changed to values specific for your project:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="your.package.name"
 android:versionCode="1"
 android:versionName="1.0" >
<uses-sdk android:minSdkVersion="4" />
<!-- Google Maps needs access to the Internet -->
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" >
<!-- Google Maps is in an external library that needs to be imported -->
     <uses-library android:name="com.google.android.maps" />

     <activity android:name=".MainActivity" android:label="@string/app_name">
         <intent-filter>
             <action android:name="android.intent.action.MAIN" />
             <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter>
     </activity>
<!-- Add this activity if you aren't showing the Google Map on your first Activity -->      <!-- android:theme="..NoTitleBar" will give the map more space by removing the title bar -->
     <activity android:name=".HelloGoogleMaps" android:theme="@android:style/Theme.NoTitleBar" />
 </application>
</manifest>

 

Second, in your HelloGoogleMaps.java file (create it if you don’t have it), have it look something like the following:

import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;

public class HelloGoogleMaps extends MapActivity {
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map);
MapView mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
    }
 /*Is required for every MapActivity*/
    @Override
    protected boolean isRouteDisplayed(){
        return false;
    }
}

 

Third, add the following code to your layout file (ex: map.xml) where you want the map to appear:

<?xml version="1.0" encoding="utf-8"?>
<!-- android:clickable allows user-interaction with the map, like panning and zooming --> <!-- The android:apiKey value will look something like 19pTmji6NUULWO2OGr5HGYNX3JEKGAqvZWqbQtx -->
<com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="Your Maps API Key goes here"
/>

Now, all you have to get is get your Android Maps API Key and replace it in the above code and you will have Google Maps in your application.

 

If there are any questions, don’t be afraid to ask.

How to Display Google Maps in Android