The Maps API & Adding a Map to your android Project

While developing Ceeq,  I had to include a Map to our application, this is how I achieved the feat.

To add a Map we first have to fulfill few requirements

1. Get the Play Services library in your project
2. Get the API key.
3. Add the permissions.
4. Add a map fragment to your activity or fragment layout
5. Install play services on device to test.
6. Run your app.

Lets get in details of each step, 

1. Get the Play Services to your project

a) Open the SDK Manager
        Eclipse > Window > SDK manager > Extras > Google Play Services  ✓ 
        Install the Google Play Services


b) The play service are downloaded to your sdk folder

         sdk > /extras/google/google_play_services/

c) Import the google_play_services to your project

        Eclipse > File > Import… > Android > Existing Android Code into Workspace,


Click Next


Click Browse  and browse to the sdk > /extras/google/google_play_services/ directory
and click Okay


Untick the samples\ and click Finish.

If all goes okay you will see google-play-services_lib in the package explorer of eclipse, now we will import it to our project.

To import it to your project right click your project and open properties
 Your_Project > Right Click > Properties or Simply press ALT + ENTER in your project to open its properties.


In the Android tab, in Library click on Add


If you have successfully imported the Google play Services to your workspace, then Select google-play-services_lib and press Okay


Click Apply and Click OK.

Thats all you have successfully imported Google Play Services to your project.

2.Let’s get the api key now

a) Login to your google account and open

b) Now create a new project and you will be at your dashboard as


c) Click on Services Tab

In the list of provided services, scroll down to Google Maps Android API v2


and switch it ON 


d) Click on API Access Tab


Click on Create New Android Key…

A dialog box opens up asking for the SHA1 key,

Now, open your Windows explorer and open your user folder, there you have the .android folder which has the debug.keystore file.


You may see this directory has a debug.keystore file

CTRL + SHIFT + Right Click and open CMD window here, or simply open a Command Window(CMD) and navigate to this directory.

Type in you command prompt

keytool -list -v -keystore debug.keystore > key.txt
it will ask for a password, type android and hit Enter.

Now, you will see a key.txt file has been generated in the os_drive:\Users\ directory. Open this file and Copy the SHA1 signature (i.e the code after SHA1:), and paste it


put a semi-colon (;) after the SHA1 code and write your package name and click Create.

You have now successfully generated your API key, which shows on your dashboard, copy the API key and put it in you manifest file as:


3. Changes to manifest file and adding the Permissions

<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=""/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

Add the uses-feature


4. Adding a map fragment to your activity layout/ fragment layout

If you are supporting backward compatibility and importing an activity or fragment activity, or for projects targeting below API14
then you need to include a SupportMapFragment to your layout

<fragment xmlns:android=""

Or else if you are not supporting backward compatibility and for projects targeting API 14+, we need to add a MapFragment to our layout

<fragment xmlns:android=""

You can get the map fragment in your onCreate() or method (incase you using fragments in onCreateView( ) ) as

For Support Map Fragment:

SupportFragment mapFragment = ((SupportMapFragment) this.getActivity().getSupportFragmentManager().findFragmentById(;

For Map Fragment:

MapFragment mapFragment = ((MapFragment) this.getActivity().getSupportFragmentManager().findFragmentById(;

5. Add play services to your emulator or device

The application is ready to test on a real device, if you have play services on it but for testing on emulator, we need google play services on it too,

So, again open the SDK Manager, Click on your relative API [mine is Android 4.3 (API 18)] and download the Google APIs. Create a new AVD with Google APIs as the platform.
Remember only Google APIs higher than 4.2.2 include play services.

You can also manually install Play Services to your virtual device via adb.

First download the files from here

After that create an AVD/emulator, any platform, and then install the downloaded files via adb as

adb install 
adb install 

if you are updating, or want to un install

adb uninstall
adb uninstall                   

So, if you now have an emulator AVD with latest Google Play Services, or you have an AVD with latest Google Play Services,
Your application is ready to run.

— Update —

For updated Play Services version 13 you need to add

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

to your manifest file so to avoid application crash.

Possible errors:

Error in Authentication this error is primary due to missing API key, missing play services, or if you have changed the API key.
1. Remove your app, wipe data of emulator/AVD, reinstall your app. 
2. Check and cross check the permissions.
3. Recheck you have enabled the Android map services from the Google APIs Console, if not enabled, Enable it, regenerate a new key, add it to your manifest, remove the application from AVD/Emulator/real device, and run your project.

Google Play Service missing this error is due to missing play services either in your test device/emulator or in the project.
1. Install the latest updated Google Play Services to the test device.
2. Recheck you have added the play services library to your project.

Error in inflating class SupportMapFragment
1. Check you have play services added to your project.
2. Try using a MapFragment if your project is for API14 and above.

No Map shown, only Zoom buttons shown
1. Remove your app, wipe data of emulator/AVD, reinstall your app. 
2. Check and cross check the permissions.
3. Recheck you have enabled the Android map services from the Google APIs Console
4. Re check you have include API key in manifest, and you have generated it via command prompt only.