You are on page 1of 9

11/3/2019 Google Map Example In Android Studio

Android
Appium
Python
PostgreSQL
Java Core
Java EE
JDBC
Maven
Spring Core
Angular JS
jQuery
Node JS
Log4j
Selenium
TestNG
Interview Questions
All Tutorials
Contact Me

Search

 Android Tutorial Google Map Example In Android Studio


Google Map Example In Android


Studio

 Jerry Zhao  March 26, 2018  0

https://www.dev2qa.com/google-map-example-in-android-studio/ 1/13
11/3/2019 Google Map Example In Android Studio

Google map is the best digital map in the world. So embed google map in
android application is very user friendly and can improve user experience.
Google provide android APIs for android developer to integrate google map
service in their android application. This article will tell you how to do it step
by step.

1. Apply Google Maps API Service Key Steps.

1. First of all, you need to create a new google APIs project. Click google
developer console to open it and login, then click CREATE PROJECT to
create one project.

2. Input the new project name and click Create button.

3. When the project creation process complete successfully, you can see
the new project in google APIs project list page.  Click the project name
and then click Google APIs menu —> APIs & Services —> Dashboard

https://www.dev2qa.com/google-map-example-in-android-studio/ 2/13
11/3/2019 Google Map Example In Android Studio

to open the project dashboard page.

4. In the dashboard page, click google maps android api link.

5. In the new page click Enable button, after a while you can go to below
page, it prompt you to create a credential first.

https://www.dev2qa.com/google-map-example-in-android-studio/ 3/13
11/3/2019 Google Map Example In Android Studio

6. In the create credentials page, select Google Maps Android API in the
drop down list then click What credentials do i need? button.

7. Then google will give you a credential by your selected API service,
because google map credential is a API key, so it give you an API key in
the next credential detail page.

8. After create the project credential, you had better configure it to restrict
it’s usage for security reason. You can follow google prompts. We just

https://www.dev2qa.com/google-map-example-in-android-studio/ 4/13
11/3/2019 Google Map Example In Android Studio

restrict it to android apps.

9. To restrict the google maps API key used only by android apps, follow
below steps.
First get the android apps package name from your
AndroidManifest.xml file.
Then get the debug SHA-1 certificate fingerprint from app / res /
values / google_maps_api.xml file. The file will be generated
automatically after you add google maps activity in you android app.
<resources>
<!--
TODO: Before you run your application, you need a Google Maps API key.
To get one, follow this link, follow the directions and press "Create" at the end:
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIEN
You can also add your credentials to an existing key, using these values:
Package name:
B1:BE:24:B9:08:60:AF:89:9B:B5:FE:64:7F:68:FD:46:32:39:21:7F
SHA-1 certificate fingerprint:
B1:BE:24:B9:08:60:AF:89:9B:B5:FE:64:7F:68:FD:46:32:39:21:7F
Alternatively, follow the directions here:
https://developers.google.com/maps/documentation/android/start#get-key
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
-->
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AIzaSyAUh
</resources>

10. Click Add package name and fingerprint button to add above value in
it, click Save button to save the result.

https://www.dev2qa.com/google-map-example-in-android-studio/ 5/13
11/3/2019 Google Map Example In Android Studio

READ :   How To Download APK From Google Play Online

2. Create Android Google Maps Example Projects.

1. Create a new android studio project.

2. Input new android project name and input project save location folder,
click next.

https://www.dev2qa.com/google-map-example-in-android-studio/ 6/13
11/3/2019 Google Map Example In Android Studio

3. In next dialog select minimum SDK version click next. In the Add an
Activity To Mobile dialog, choose Google Maps Activity, click next and
input related data and click Finish button.

4. If it show you below error messages in bottom Messages tab, then


click Install missing platform(s) and sync project link to install the
missed android sdk.

https://www.dev2qa.com/google-map-example-in-android-studio/ 7/13
11/3/2019 Google Map Example In Android Studio

Error:Failed to find target with hash string ‘android-26’ in:


C:\Users\Jerry\AppData\Local\Android\Sdk
5. After that open app / res / values / google_maps_api.xml file in left
android project panel. In the xml file detail content in right panel, 
replace the string placeholder YOUR_KEY_HERE with the google maps
api service credential key you just generated in section 1.

6. Find Google Maps API related play services description in this url
: https://developers.google.com/android/guides/setup

7. Open project build.gradle file, add above google maps API dependency
library in it. You can find the dependency has been added by android
studio automatically.

https://www.dev2qa.com/google-map-example-in-android-studio/ 8/13
11/3/2019 Google Map Example In Android Studio

com.google.android.gms:play-services-maps:12.0.0

8. Click and open app / res / layout / activity_google_maps.xml file. You


can see that a Fragment has been added to this layout xml file
automatically by wizard also.
9. Click and open GoogleMapsActivity.java file, you can also find wizard
has add code skeleton for you, so if you do not need to add more
function, this app can be executed right now.

 Posted in Android Tutorial


 Tagged Android Map

 LEAVE A REPLY

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

https://www.dev2qa.com/google-map-example-in-android-studio/ 9/13

You might also like