Loading the Google Maps on Android Mobile / Simulator
Follow the following link to generate the map key
http://code.google.com/android/add-ons/google-apis/mapkey.html
Command to load the debug.keystore
C:\Java\jre\bin>keytool.exe -list -alias androiddebugkey -keystore "C:\Documents and Settings\jit\.android\debug.keystore" -storepass android -keypass android
on Enter you will get a privateKeyEntry with Certficate FingerPrint (MD5)
Once the MD5 finger print is generated
Registering the Certificate Fingerprint with the Google Maps Service
http://code.google.com/android/maps-api-signup.html
Note: Make sure the simluator is set to Google 2.X API
Program to Load Google MAP on Android
--------------------------------------
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
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:enabled="true"
android:apiKey="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
/>
</LinearLayout>
----------------------------------------
AndroidManifest.xml
----------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jit"
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=".GMap"
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-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"></uses-permission>
</manifest>
------------------------------------------------
GMAP.Java
-------------------------------------------------
package com.jit;
/*
* @author: Vinay Guntaka
*/
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.Toast;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
public class GMap extends com.google.android.maps.MapActivity{
MapController mMapController;
MapView mMapView;
GeoPoint p;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mMapView = (MapView) findViewById(R.id.webview);
mMapView.setBuiltInZoomControls(true);
mMapView.setSatellite(true);
mMapController = mMapView.getController();
mMapController.setZoom(15);
//mMapView.setSatellite(true);
mMapView.setStreetView(true);
String coordinates[] = {"1.352566007", "103.78921587"};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));
mMapController.animateTo(p);
mMapController.setZoom(17);
mMapView.invalidate();
/* MyOverlays myOverlays = new MyOverlays(this.getResources().getDrawable(R.drawable.icon), this);
OverlayItem tempOverlayItem = new OverlayItem(new GeoPoint(17000000,78000000), "NewActivity", "Welcome to New Activity");
tempOverlayItem.setMarker(this.getResources().getDrawable(R.drawable.icon));
myOverlays.addOverlay(tempOverlayItem);
mMapView.getOverlays().add(myOverlays);*/
}
@Override
public boolean onTouchEvent(MotionEvent event) {
Toast.makeText(this, "Ooops! I am touched", Toast.LENGTH_LONG).show();
return super.onTouchEvent(event);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
------------------------------------------
No comments:
Post a Comment