Saturday, September 8, 2012

Map Example In Android

This example of will show how we can show and use google map into our application.
1.) Create a new project by File-> New -> Android Project name it MapExample.
2.) You will see some default code into your main.xml, strings.xml and android manifest file.
3.) Now create your MD5 fingerprint and map API key. To generate MD5 fingerprint open command prompt and change the directory to your jre path. Run keytool command to check the path is correct or not.
Enter following command: keytool -list –v -alias androiddebugkey -keystore “ .keystore” -storepass android -keypass android
Check to get more information.
4.) Add following library and permissions to your manifest file:
<uses-library android:name="" />
<uses-permission android:name="android.permission.INTERNET" />

        <uses-permission android:name="android.permission.ACCESS_GPS" />
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
1.) Create a project named MapExample and set the information as stated in the image.
Build Target: Android 2.1
Application Name: MapExample
Package Name: MapExample
Activity Name: MapExample
Min SDK Version: 7
2.) Open file and write following code there:
import java.util.List;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
public class MapExample extends MapActivity {

        /** Called when the activity is first created. */
         private Location myLocation;
     protected MapView myMapView = null;
     protected LocationManager myLocationManager = null;
     protected MapController mapController;
     List<Overlay> mapOverlays;
     protected boolean isRouteDisplayed() {
             // TODO Auto-generated method stub
             return false;
     protected void onCreate(Bundle icicle) {
             // TODO Auto-generated method stub
             this.myMapView = newMapView(this,"0jp8vWjNayJISFKdvcJwGmwsjgoCoQrT_dflCfQ");
                mapController = myMapView.getController();
                mapOverlays = myMapView.getOverlays();
                this.myLocation = new Location("gps");
     private void updateView(){
     Double lat = myLocation.getLatitude();
     Double lng = myLocation.getLongitude();
     GeoPoint point = new GeoPoint(lat.intValue(), lng.intValue());
3.) Compile and build the project.
4.) Run on 2.1 simulator which has google api support for the output.

No comments:

Post a Comment