This is the Tutorial for adding Google Maps V2 to your Android Project.
 MapV1 is depracted, you cannot generate Map API - key anymore using MD5.

With the Google Maps Android API, you can add maps based on Google Maps data to your application. The API automatically handles access to Google Maps servers, data downloading, map display, and response to map gestures. You can also use API calls to add markers, polygons, and overlays to a basic map, and to change the user's view of a particular map area. These objects provide additional information for map locations, and allow user interaction with the map. The API allows you to add these graphics to a map:
  • Icons anchored to specific positions on the map (Markers).
  • Sets of line segments (Polylines).
  • Enclosed segments (Polygons).
  • Bitmap graphics anchored to specific positions on the map (Ground Overlays).
  • Sets of images which are displayed on top of the base map tiles (Tile Overlays).
  • Maps are stored in SD Card.
  • Loads Faster
Step : 1
Before you start generate you API Key

 Install Google Play Services in your SDK.

* click of the images to view larger


Step : 2
 Import  Google Play Service Library into your workspace.
  1. Select File > Import > Android > Existing Android Code Into Workspace and click Next.
  2. Select Browse..., Open <android-sdk-folder>/extras/google/google_play_services/libproject/google-play-services_lib and click Finish.


Step : 3
Create a new Project with GoogleAPIs.

Step : 4
Add Google_Play_Services as a supporting Library to the Project




Open  "AndroidManifest.xml" 

Add the following before closing </application>

REPLACE YOUR API_KEY

<meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="YOUR_API_KEY_GOES_HERE" />


Add following permission, changing your "Package Name"

    <!-- Change "vee.mapsv2.demo" with your package name -->

    <permission
        android:name="vee.mapsv2.demo.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="vee.mapsv2.demo.permission.MAPS_RECEIVE" />

    <!-- Change "vee.mapsv2.demo" with your package name -->


Add following permission, directly


    <!-- Access Internet -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />

    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

    <!-- External storage for caching. -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <!-- Location -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <!-- Maps API needs OpenGL ES 2.0. -->
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />



Now "AndroidManifest.xml" should look like this


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="vee.mapsv2.demo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="17" />

    <!-- Change "vee.mapsv2.demo" with your package name -->

    <permission
        android:name="vee.mapsv2.demo.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="vee.mapsv2.demo.permission.MAPS_RECEIVE" />

    <!-- Change "vee.mapsv2.demo" with your package name -->


    <!-- Access Internet -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

    <!-- External storage for caching. -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <!-- Location -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <!-- Maps API needs OpenGL ES 2.0. -->
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:hardwareAccelerated="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity android:name=".MainActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="YOUR_API_KEY_GOES_HERE" />
    </application>

</manifest>


Replace the below code in "activity_main.xml"

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/map"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  class="com.google.android.gms.maps.SupportMapFragment"/>


Tasks Performed


✪ Check whether Maps is loaded or not
✪ Once Loaded, Add Marker at Custom "Latitude" & Longitude".
✪ Set the MapType
✪ Use CameraUpdateFactory to Move Camera & zoom to custom level.
✪ Retain current state on Orientation Change.

MapView has been deprecated, instead uses normal Activity.

Maps are encapsulated in the MapFragment class, you can implement them by extending the Android standard Activity class, rather than extending the MapActivity used in version 1.



Replace the below code in "MainActivity.java"



package vee.mapsv2.demo;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity extends FragmentActivity {
 GoogleMap map;
 double latitude = 12.971689;
 double longitude = 77.594504;

 LatLng latlon = null;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  latlon = new LatLng(latitude, longitude);
  setUpMapIfNeeded(); // Required to check the availability of Maps

 }

 @Override
 protected void onResume() {
  super.onResume();
  setUpMapIfNeeded();
 }

 private void setUpMapIfNeeded() {
  if (map == null) {
   /*
    * I avoid Crashing, if Google_Play_Services is not Updated or
    * Unavailable
    */
   map = ((SupportMapFragment) getSupportFragmentManager()
     .findFragmentById(R.id.map)).getMap();
   /*
    * To make sure map is loaded
    */
   if (map != null) {
    setUpMap();
   }
  }
 }

 private void setUpMap() {
  /*
   * Add a Marker Adding marker at 12.971689,77.594504;
   */
  map.addMarker(new MarkerOptions().position(latlon)

  /*
   * Add Title when clicked on marker
   */
  .title("Title")
  /*
   * Add Snippet when clicked on marker
   */
  .snippet("I am a looooooooooooooong Snippet"));

  /*
   * NormalMapView
   */
  map.setMapType(GoogleMap.MAP_TYPE_NORMAL); // Normal MapView

  /*
   * Move Camera to Snippet Location
   */
  float zoom = 11;
  map.moveCamera(CameraUpdateFactory.newLatLngZoom(latlon, zoom)); // toPosition,
                   // ZoomLevel
 }

 @Override
 protected void onPause() {
  super.onPause();
 }

 @Override
 protected void onDestroy() {
  super.onDestroy();
 }

 @Override
 public void onLowMemory() {
  super.onLowMemory();
 }

 @Override
 public void onSaveInstanceState(Bundle outState) {
  super.onSaveInstanceState(outState);
 }
}


Download SourceCode

When you run the app, you should be seeing this
 YOU CANNOT RUN MAPSV2 in EMULATOR by default, as it USES GOOGLE PLAY SERVICES.