//
you're reading...
HCI, Tech

Six Steps to Load the First Google Map in Your Android Application

1. Get Your MD5 Fingerprint

This page offers all the information needed (http://code.google.com/android/add-ons/google-apis/mapkey.html#registering).

Speaking for Windows:

  • The first step is to locate keytool, usually at “Program Files/Java/jdk[version#]/bin/”;
  • The next step is to locate the debug.keystroke, usually at “Users\[user name]\.android\”;
  • Then run the following:
    • keytool -list -alias androiddebugkey -keystore <path_to_debug_keystore>.keystore -storepass android -keypass android

If successful, you will be prompted with a xx:xx:xx…:xx formated type of MD5 key.

2. Obtain API Key

Take that MD5 key and go to http://code.google. com/android/maps-api-signup.html. Proceed to get your API key.

3. Create a Google-APIs-based Android Project

Now go to the IDE and create a new Android Project, but set the build target to Google APIs (with the same platform number).

4. Modify the AndroidManifest.xml

In the created project, add two lines to the AndroidManifest.xml:

  • As a child node of <application>:
    • <uses-library android:name="com.google.android.maps" />
  • As a child node of <manifest>:
    • <uses-permission android:name="android.permission.INTERNET" />

5. Create a Layout XML

To make things easier, just copy-paste from an existing example:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/mainlayout"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent" >
<com.google.android.maps.MapView
 android:id="@+id/mapview"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:clickable="true"
 android:apiKey="your api key"
 />
</RelativeLayout>

6. Create a Class Extending MapActivity

The ‘main’ class should extend MapActivity (com.google.android.maps.MapActivity), looking something like this:

import android.os.Bundle;
import com.google.android.maps.MapActivity;
public class HelloMap extends MapActivity {
@Override
 protected boolean isRouteDisplayed() {
 // TODO Auto-generated method stub
 return false;
 }
 
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);
 } 
}

You should be good to run by now.

Advertisements

About Xiang 'Anthony' Chen

Making an Impact in Your Life

Discussion

Trackbacks/Pingbacks

  1. Pingback: Three (More) Steps to Use GestureDetector in MapActivity « A Designer with Dirty Hands - November 30, 2011

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Twitter Updates

%d bloggers like this: