Google Maps in Android


Without a doubt, maps are one of the most useful tools for users when included in an app. This tutorial is the first in a series going over Google Maps v2 for Android. It will cover setting up the Google Maps API through the Google Developer Console, including a map fragment in your applications, displaying the user’s location, adding markers, drawing on the map, and some general methods that will add utility to your app.

Setting Up the Developer Console

In order to use the Google Maps API, you must register your application on the Google Developer Console and enable the API. To do this, start by going to the Google Developer Console. If you already have a project created, you can skip the next section. If not, you can follow along and create a new project for your maps application.

Step 1: Creating a Project
To create a new project, click on the blue Create Project button in the top left corner of the screen. If you don’t see a Create Project button, then look for a button labeled Create an empty project.


This presents you with a dialog that asks for a project name. For this tutorial, I have created a project called TutsPlusMaps. There are some restrictions on what you can name your project as only letters, numbers, quotes, hyphens, spaces, and exclamation points are allowed characters.


Once you hit Create, a dialog appears in the lower right corner of the page with a loading indicator while the project is being created.

Step 2: Enabling the Maps API
When the project has been created, or you have selected an existing project, you are taken to the project Overview screen. From here you will want to expand the APIs & auth item in the left navigation panel and click on APIs.


While there’s a search box on this screen, you’ll notice that Google placed the Maps API items at the top of the center column for developers to access. For this tutorial, click on the item titled Google Maps Android API under the Google Maps APIs heading.


This takes you to a screen where you can click on the blue Enable API button in order to enable the Maps API for your project.


Step 3: Creating an Android API Key
After you’ve enabled the Maps API, click on the Credentials item under APIs & auth in the side navigation to get a key to access the Maps API in your application. When you are presented with the Credentials dialog, press the blue Add Credentials button and select API Key.map6

Since this is an Android application, you need to select Android Key in the next dialog. If you were to create the same application using maps on different platforms, you could create a key for each platform.


On the next screen, click Add package name and fingerprint. This provides two fields, one for adding a package name and another for adding the SHA1 from your application signing key.

For this tutorial, I will use the package name com.tutsplus.mapsdemo. To get the SHA1 signature, you need to open a terminal or command prompt and navigate to the location of your application’s signing key. This can be either your release key or debug.keystore. You can generate the SHA1 with the following command:


After you have created your SHA1 key and entered it into the text field, click on the blue Create button. You are then presented with a dialog containing the API key that you need to add to your Android app to access the Maps API.


After this Create one new project


Permission in manifest.xml

Add below dependencies in build.gradle


Leave a Reply