Thursday, 29 August 2013

Google maps v2 for Android - Basic start point guide

The second version of Google Maps for Android was release on December 2012 and beside the 3D maps, it facilitated a lot of works for the developers.

This basic guide try to mark a start point with all the steps that a developer should do in order to use it in Android.

1. Download the library
By default the library is not included in the SDK. To download, follow the steps below:
1.1 Click on Windows -> Android SDK Manager
1.2 Under Extras, mark the "Google Play services" and install it.

2. Import the Google Play library
Once done, it will appear as project the "extra" folder of your SDK installation folder. You must import it to Eclipse.
2.1 Click on File -> import
2.2 Select Android -> Existing Android Code Into Workspace and then click on Next
2.3 Click on Browse and go to the YOURSDKFOLDER/extras/google/google_play_services/libproject/google-play-services_lib
2.4 Click on Accept to import the project.

3. Create a new Android project
3.1 Click on File -> New -> Android Application Project
3.2 Enter the data. They could be:
- Application Name: Sample Google Maps v2
- Project Name: SampleGoogleMapsv2
- Package Name:
3.3 Click next several times and then Finish.

4. Import the Google Play library in your project
4.1 Right click on the created project and select "Properties"
4.2 On the left panel, select "Android"
4.3 On the right panel, click on Add and select "google-play-services_lib"
4.4 Click on Ok 2 times to finish

5. Get the SHA-1 key
5.1 Open the console
5.2 Write the follow command and click enter to show all the keys

keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

It will show a list of keys. The unique one we are going to use is the one called SHA1. It could be something like this:


6. Activates the Google Maps v2 API for Android
6.2 Sign in with your Google account if you haven't done it yet.
6.3 On the left panel, click on Services
6.4 On the right panel go to the one called "Google Maps Android API v2" and enable the switch
6.5 Read carefully the contract :-) and accept it.
6.6 Once it is done, the API for Google Maps for Android has been activated

7. Get the API key
7.1 On the same screen of Google APIs console. on the left panel, click on API Access
7.2 Click on the button called "Create new Android key" at the bottom of the page.
7.3 On the popup windows, enter your SHA-1 key along with the package name of your application, separated by a semicolon. For example, this could be:


A new API key will be created. It is something like this:


Save it because we are going to use it later.

8. Creates the layout.
Paste the follow code in the activity_main.xml

<RelativeLayout xmlns:android=""
    tools:context=".MainActivity" >

        class="" />


9. Creates the activity.
Paste the follow code in the


import android.os.Bundle;
import android.view.Menu;

public class MainActivity extends Activity {

protected void onCreate(Bundle savedInstanceState) {

public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(, menu);
return true;

10. Modify the Manifest file
Copy and paste the follow code to the Android Manifest file.
Don't forget to copy and paste your API key from the step 7.3 to "YourAPIGoesHere".

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

android:targetSdkVersion="17" />

        android:protectionLevel="signature" />

        android:required="true" />

    <uses-permission android:name="" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="" />
    <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_NETWORK_STATE"/>

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


Source Code:

No comments:

Post a Comment