Thursday, 7 March 2013

Google Maps Android API v2

NOTE: Version 1 of the Google Maps Android API has been officially deprecated as of December 3rd, 2012 . This means that from March 3rd , 2013 you will no longer will able to request an API key for this  version. No new features will be added to Google Maps API v1 . However , apps using v1 will continue work on devices. Existing and new developers are encouraged to use Google Maps Android API v2.

NOTE: You cannot run your application using Google Play API(Google Maps Android API V2) on Android emulator, Because your emulator doesn't support Google Play services. So you need to check your application in Android mobile phone which supports google play services.

watch video tutorial here:click here

download this project here :GoogleMapsAndroidAPIV2 

Here i'm giving the procedure how to setup Google Map Android API v2 SDK and integrating in Application.


Step1: Download and configure the Google Play Services SDK. In Eclipse open go to window menu
          and run Android SDK Manager and under Extras select Google Play Services package and
         download it.

Step 2: Now create your application where you want use Google maps api v2.

Step 3: Import Google Play Services library project in eclipse

  • Under package explorer right click choose import option and under android choose importing existing project into workspace as  follows.

  • In next window choose browse option and open your ADT Bundle has been located or your Android SDK and inside open extras folder and open google folder and open google_play _service folder and choose libproject folder and click ok button.

  • After clicking ok button under Import Project window select google play service lib project and click finish button.

  • After clicking finish button you will observe in under package explorer google_play_services_lib project has been added.

Step4: Adding googleplay_services_lib to our project:
  • Right click on project and choose properties option and select android .
  • Under library choose add option and add googleplay_service_library to our project as follows:


Next again perform same action.
  • Right click on project and choose properties option and select android and if you got following error under library then follow the bellow procedure.

Note: you will get this problem because of lengthy path.

open adt bundle -->open sdk folder-->open extras folder-->open google folder-->open googleplayservices folder-->copy lib project and paste in your current workspace folder and from there import libproject after importing add library to the project now you wont get any error.

Step5: Finding SHA1 fingerprint key

Now two ways are avialable to findout SHA1 key 
  • Go to window menu choose preferences under preferences choose android under that choose build and copy SHA1 fingerprint key as follows:


Procedure 2:
  • If your using windows operation system follow below procedure
  1. Under package explorer right click and choose properties.
  2. Under Android choose build and there you can see default debug keystore copy that keystore value.
  3. After goto MyComputer and open the drive where your operating system has been located and under that drive open program files folder there you will see java folder open that and open jre folder on bin folder click SHIFT+Right click choose open command window here and type following command.
  4. keytool -list --alias androiddebugkey -keystore "paste your default debug keystore here" -storepass android -keypass android
  5. After executing above command you will get SHA1 certificate fingerpint key copy that and go to internet and in Google type google api console and there sign in using your google account.
  • If your using Mac or Linux operating system procedure is very easy just type following command in Terminal
  • keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

After executing above command you will get SHA1 certificate fingerpint key copy that and go to internet and in Google type google api console and there sign in using your google account.

Step 5: Sign in google api console website as follows


Step 6: After signing in follow the steps below

  • -->Under google api's console select create project option as follows

-->provide project name and select create button.

-->After selecting create button you will get following window.
-->In following window from left side navigation bar select APIs & auth option as follows

-->In following window scroll down and activate Google Maps Android API v2 Services by clicking on OFF button to ON


-->Select Credentials option from left side navigation bar under APIs option

-->After selecting Credentials option next you will get following window 
-->From following window select CREATE NEW KEY option

  • In following window enter your SHA1 cerficate fingerprint key (go to step5)with semicolon and after enter your application package name as follows.
  • And click create button.

-->After selecting create button you will get following window from following window you can copy the map API key and insert into AndroidManifest.xml.

Step 7: Go to eclipse open your application and open AndroidManifest.xml file and insert following code .


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    android:versionName="1.0" >

        android:targetSdkVersion="17" />
        android:required="true" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="" />
     The following two permissions are not required to use
     Google Maps Android API v2, but are recommended.
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

        android:name="your application package name.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="your application package name.permission.MAPS_RECEIVE" />

        android:theme="@style/AppTheme" >
            android:label="@string/app_name" >
                <action android:name="android.intent.action.MAIN" />

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

            android:value="@integer/google_play_services_version" />

            android:value="paste your api key here" />


Step 8: Insert following code in your activity_main.xml


<LinearLayout xmlns:android=""
    android:orientation="vertical" >


Step 9: Insert following code in your
package com.ram.googlemapsv2;

import android.annotation.SuppressLint;
import android.os.Bundle;


public class MainActivity extends Activity {
GoogleMap map;
protected void onCreate(Bundle savedInstanceState) {

map = ((MapFragment) getFragmentManager().findFragmentById(
// map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
// map.setMapType(GoogleMap.MAP_TYPE_NONE);
// map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
// map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);