Generate Google Maps Key in Android

Introduction

This article explains how to generate a Google Maps Key in Android.

What is API


API stands for Application Programming Interface that consisits of packages, classes and interfaces with their respective methods, fields and constructors. APIs are used to minimize the lines of code that you write to develop an application.

Google Maps API

The Google Maps API provides you the ability to add Google Maps to your application. The Google Maps API automatically deals with the Google Maps server, data downloading, map display and touch gesture on the map. Using this API you can also add markers to the Google Maps. The Google Maps Android API provides a MapView class.

MapView

A Map View is a View that displays a Map by obtainning data from the Google Maps service. When you use this class you need to forward all the lifecycle methods from the activity or fragments. The methods you will forward are as follows:

onCreate()

onResume()

onPause()

onDestroy()

onSavedInstanceState()

onLowMemory()

You can get Google Maps using the getMap() method of the MapView class. But the Map availability is totally dependent on the Google Play service APK. To use Google Maps you need to first install the Google Play service and get a Google Maps key from Google. Otherwise the getMap() method returns null.

For a simpler method of displaying a map use MapFragments.

getMap()
  

This method is used to get the Google Maps. This method returns null when the Google Maps is not available and this happens when the Google Play service is not available. If the Google Play service is available then it returns the Google Maps.

Generate Google Maps key

Now we will learn how we generate the Google Maps for the Android application.

Step 1

First you need to install the Google Play service on clicking the Android SDK Manager.

appmap2

Step 2

After installing the Google Play service you need to import the Google Play "service_lib" like this:

appmap3



Step 3

Click "File" -> "Import".




Step 4

Click "Android" then click on the existing Android code in the workspace .

appmap4


Step 5

Click on "Browse".

appmap5

Step 6


Go to the SDK then select "Extras"-> "Google"-> "google_play_service" -> "libproject" then click "Ok" and "Finish". Now you can see in your project explorer list the "google_play_service_library" like this:

appmap6


Step 7


Now add the library to your project like his:

Right-click on your project then select "Properties" -> "Android" then click on "Add".

appmap7

Click "Ok" then click "Apply" then click "Ok" again. Now your library will be added to your project.

appmap8

Step 8

Now go to the Google API console on your browser.

appmap9

Step 9

Click on the services.

appmap10

Step 10

Switch on the Google Maps API version 2 like this:

appmap11

Step 11


Now click on the API Access.

appmap12

Step 12

Click on the create new Android key.

appmap13

Step 13

Now in your cmd write this:


keytool -list -v -keystore " path of your debug key store"-alias androiddebugkey -store android -key android
appmap14

Then click Enter. Your fingerprint is generated.

Step 14


appmap15 

Now copy the SHA1 and paste it here.


appmap16
Click "Ok" and your key will be generated.

Your key will be look like this:
AIzaSyCGH71e5druEOzLfHqVNUn50VY0RXRCr_E


Up Next
    Ebook Download
    View all
    Learn
    View all