Android Google Maps Api v2

I finally decided to make a new post about the latest way of integrating Google Maps in Android applications. Please note that Google Maps Api v1 is now deprecated and supported by Google any more, so this is deprecated too. So you have to do some preliminary steps first.

What tools did I use?

  • Android Studio
  • Gradle
  • As emulator I use Genymotion which is a lot faster than the Android Emulator,  and it’s free for non-commercial use. But if you use Android emulator: “Firts of all you have to run the application with Google APIs add-on! To do this, go to AVD manager and create an emulator using  GoogleApis.(example: if you have Android 4.3 Platform you must change it to Google APIs (Google Inc. ) – API Level 18)). “

First create a new project and make sure you have the java class called MyActivity (like in this tutorial) and a xml file for layout which should be called my_activity_layout.xml. So this xml should be found under res – layout – my_activity.xml.

Preliminary Steps

1.  You have to make sure you have the Google Play Services installed and up to date. You can check if you have it from SDK Manager (Tools – Android – SDK Manager and you should find it under Extras)

2.  Now that you are sure that you have Google Play Services you should add them to you project. In order to do this you should go to build.gradle and add this line of code to dependencies and then tap the sync button that appears in the right corner of the screen.

compile ''


3.  Now you should open your AndroidManifest.xml file and add this code within the application tags.

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

Get an Android SHA1 Certificate Fingerprint

Even if you already have a certificate and key, for the v2 version you have to get new ones, because the  mechanism used now is different from the v1 version and the old certificates don’t work for v2.

Step 1: If you test your application with the emulator you must find debug.keystore. To find it, press the Windows start button and make a search for debug.keystore and press right click on it and select Open File Location. If you can’t find it in this way you should know that in general the debug.keystore is localized inC:\Users\name_of_your_PC\.android. After you find it, make a folder in “C:\”, called “Android”, so you have something like this: “C:\Android”. In this folder copy the debug.keystore

Step 2: Now open cmd and change the default path to where your Java is installed. In my case it is installed in C:\Program Files\Java\jre6\bin. So, to get to this path you have to use the command “cd..” until you have only “C:\”. After this, type “cd Program Files”-press enter button – “cd Java” – press enter button – “cd jre6″ – press enter button – “cd bin”- press enter button. Of course if your Java files are installed somewhere else you have to change the directory to where they are. You have to get to Java\bin because here is the keytool.

Step 3: Enter the following in the cmd code and press enter, but first you might need to delete the quote marks ‘ ” ‘ and insert them again from your keyboard,  because there are some issues with the font :
keytool.exe -list -v -alias androiddebugkey -keystore “C:\android\debug.keystore” -storepass android -keypass android

SHA1 Certificate Fingerprint

You will need the SHA1 certificate fingerprint.

Get Google Maps Api key

1.  Open Google APIs Console from your browser.

2. In the left menu, click on Services and enable Google Maps Android API v2.


Google Maps Android API v2 ON

3.  Now, click on API Access in the left menu and after the page is loaded click on Create New Android Key button.

API Access


4. In order to create the Android Key you have to introduce

SHA1 Certificate + “;” +  Your project package name

In our example we would have something like this:


If you have trouble reading your package name you can easily read it from AndroidManifest.xml file at “package” tag.

Now you obtained the API key and you can introduce it to your project.
1.  Add you API Key to your project by adding this code in AndroidManifest.xml file just before the </application> tag closes

So a concrete example is something like this:


2.  Add permissions

You have to set the following permissions:

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

Also you can set these 2 permissions as Google recommends them to be set, but they are not required.

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

3.  Specify requirement for OpenGL ES version 2. OpenGL is necessary for rendering the map,  and this prevents Play Store from displaying the app on devices that don’t support OpenGL ES version 2.  Also this notifies external services that OpenGL is required.


NOTE: This is the final AndroidManifest.xml file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    package="funcode.googlemaps" >

    <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"/>


        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" />



4.  Now go to layout xml (res – layout – my_activity_layout.xml) and make sure you have exactly the same code as below:

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

5. Now go to MyActivity and add the following code:

import android.os.Bundle;

public class MyActivity extends Activity {

    protected void onCreate(Bundle savedInstanceState) {

And that’s it. Now the new Google Maps API v2 should work for you too.


I really hope this tutorial helped you. For any questions or suggestions please comment below.

Exit mobile version