Google Map Integration In Android Studio Tutorial Example | Maps API Key

Today’s tutorial is about google map integration in android studio example.

We learn how to integrate google maps in your android app using maps API.

Every location based application need to have google map in it’s functionality.

It allows user to show different places and addresses efficiently and effectively.

Travel based applications, Taxi apps like uber etc. uses map feature to enhance the User experience.

For this tutorial, we need to work at two different places.

First is google developer console where we will need to create an app, enable the maps API and to get API_KEY.

After this, we need to integrate this API_KEY with our android studio project.

Work At Google Developer Console

So let us make necessary work at the google developer console.

Step 1. Creating New Project

Click on the below link to go to google developer console:

https://console.developers.google.com

Now it will open the dashboard for developer console.

It will look like below image

google map integration in android

Creating New Project

  • You may see different screen than above image if you are already log in the Google account.
  • Just find out an option to create new project or select project, mostly it is at the top bar at left corner.
  • Click on Create button to make new project.

After clicking the create button, you will see the screen like the below image.

google map integration in android

Enter New Project Details

  • Enter your desired project name first. Then select your country.
  • Then after, select radio buttons as per your choice and click the Create button.
  • Now we have successfully created new project in developer console. It is time to enable the Maps API.

Step 2. Enabling Maps API for Android

When you click the create button, system will open a screen like the following image.

google map integration in android

Selecting Maps SDK For Android

  • You will see several options like Google Drive API, Gmail API etc.
  • Click on the Maps SDK for Android option.

System will led you to the screen like the below image.

google map integration in android

Clicking Enable Button

  • Just click the ENABLE button and our Maps API for our project is successfully enabled.

Step 3. Getting Final API Key

When you click on the ENABLE button, system will open a dashboard like following image.

google map integration in android

Dashboard

  • By default, at the left sidebar, APIs option is selected.
  • In the main middle scree, there are three tabs at the top bar:  Metrics, Quotas and Credentials.
  • Click on the Credentials tab. System will open following screen now.
google map integration in android

Creating Credentials

  • There is a button named “Create credentials”, click this button.
  • It will create a pop up like shown in the above image. There are three options here. Select the first option called “API key”
  • When you click on the “API key” option, system will open one dialog box which looks like the below image.
google map integration in android

Getting Final API key

  • Here you have got your final API key. We will use this API key in our android studio project so copy it in notepad.

Working on Android Studio

Step 1. Build.gradle file

  • When you create a new project in android studio, select default activity as “Empty Activity.” This will method of implementing map is easy to integrate map in existing application with other codes.
  • Do not select “Google Maps Activity“. If you want to select this activity then I have explained about this scenario later in this tutorial.

Write down the below line in your build.gradle(Module: app) file

  • It will fetch all the required classes to integrate the google map.

Step 2. Changing Manifest File

Now you need to add meta data and uses-feature tags in the AndroidManifest.xml file.

Add the below source code just after the <application> tag

  • In the above code, use need to write your API key, that we just create from the google developer console.
  • Replace YOUR API key with your key in the above code.

Now add the following code  after the </application> tag ending.

Full source code for AndroidManifest.xml file will look like

Step 3. Main Layout

Now we just need to change activity_main.xml file

Add the below code in it

After this, you should get the output like the below image

google map integration in android

Final Output

Second Method For Android Studio

Now create another new project in android studio.

This time select “Google Maps Activity” as a default activity as per below image.

google map integration in android

Select Google Map Activity

  • When this activity is created, we just need to change one file : google_maps_api.xml
  • google_maps_api.xml is located under res->values directory.
  • In this file, we need to add our API key. See the below source code

After this, run your project and you will get your google map.

Shining Google Map Examples

Here are some awesome and time saving tutorials

Download Source Code For Google Map Integration in Android

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *