Android - Using Google Maps

by Bar Zohan 2. November 2010 02:36

Step 1 - Getting your MD5 Fingerprint

Use the "Keytool.exe" that can be located inside "C:\Program Files\Java\<YOUR INSTALLED JDK DIR>\bin"

Use the following command on "Keytool.exe";

keytool.exe -list -alias androiddebugkey -keystore "C:\Users\<your windows user>\.android\debug.keystore" -storepass android -keypass android

Step 2 - Getting Your Android Maps Api Key

Open page "http://code.google.com/intl/en-EN/android/maps-api-signup.html" with your browser. Enter your Fingerprint and get your api key.

Step 3 - Setting up Permissions

Open file "AndroidManifest.xml". Add this line to the "<manifest>" node of the current xml.


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

And add the following line to the "<application>" node.


<uses-library android:name="com.google.android.maps" />

After all your "AndroidManifest.xml" should look something like this:


 
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="pckg"
      android:versionCode="1"
      android:versionName="1.0">
   <uses-permission android:name="android.permission.INTERNET" />
    <application android:icon="@drawable/icon" android:label="@string/app_name">
   <uses-library android:name="com.google.android.maps" />
        <activity android:name=".Act"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="4" />
</manifest> 
 

Step 4 - Creating A MapView Object

Import these classes to an Activity class in which you're going to create and use the MapView object.

 

import com.google.android.maps.MapActivity;

import com.google.android.maps.MapView;

 

Now do not extend this class from "Activity" instead extend it from "MapActivity".

Implement the nescessary functions which are "isRouteDisplayed()" and "onCreate(Bundle savedInstanceState)"

Now create a new MapView object inside the "onCreate" function that's overridden. 

Final code should be something like this.

public class MyMapActivity extends MapActivity {

    @Override

    protected boolean isRouteDisplayed() {

         return false;

    }

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        MapView Map = new MapView(this,"YOUR MAP KEY HERE");

    }

}

 

 

That's it ;)

Tags: , , ,

Android | Java

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About the author

Page List