Google Maps

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<com.google.android.maps.MapView
android:id="@+id/myGMap"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:enabled="true"
     android:clickable="true"
        android:apiKey="0YaGLMeMFKXrhzHL-uSYZSnqXqbGwE6kxF4VwFQ"
    />


</LinearLayout>

Androidmanifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="moor.android.map"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <uses-library android:name="com.google.android.maps" />
        <activity android:name="moor.android.map.SampleMapActivity"
                  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="3" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
   
</manifest> 

SampleMapActivity.java

package moor.android.map;

import android.os.Bundle;
import android.view.KeyEvent;

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

public class SampleMapActivity extends MapActivity {
   
    MapView            myMapView        = null;
   
    MapController    myMC            = null;
   
    GeoPoint        geoPoint        = null;
   
    double            latitude        = 12.937875, longitude = 77.622313;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        myMapView = (MapView) findViewById(R.id.myGMap);
        geoPoint = new GeoPoint((int) (latitude * 1000000), (int) (longitude * 1000000));
        myMapView.setSatellite(false);

        myMC = myMapView.getController();
        myMC.setCenter(geoPoint);
        myMC.setZoom(15);

        myMapView.setBuiltInZoomControls(true);
        myMapView.displayZoomControls(true);

    }
    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }
   
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_I) {
            myMapView.getController().setZoom(myMapView.getZoomLevel() + 1);
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_O) {
            myMapView.getController().setZoom(myMapView.getZoomLevel() - 1);
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_S) {
            myMapView.setSatellite(true);
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_M) {
            myMapView.setSatellite(false);
            return true;
        }
        return false;
    }

}

Screen shot :


Obtaining a Maps API Key for Version 1:


C:\>keytool -v -list -alias androiddebugkey -keys
tore .android\debug.keystore -storepass android -keypass android

It will getnerate a certificate fingerprint (MD5) in this format:

Certificate fingerprint (MD5): XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX

Note: Go to the page for obtaining the Maps API Key and get your key.




 Obtaining a Maps API for Version 2:

 Follow this link and proceed....

https://developers.google.com/maps/documentation/android/start


2 comments: