Thursday, July 28, 2016

How to use Google Map API in Android.

How to use Google Map API in Android.
1- you need to create Google API Key
https://developers.google.com/maps/documentation/android-api/
Image1
Click on get Key and follow the process till you get the below screen showing Google API Key
Image2
2- Now create a certificate so that we can authenticate our request using belwo commands
keytool -list -v -alias androiddebugkey -keystore C:\xyz\.android\debug.keystore -storepass android -keypass android
3- Go to
https://code.google.com/apis/console/
if you had already created a project in that case it will direct it to you on below pages
https://console.developers.google.com/iam-admin/projects
Select service accounts from left tab and select your project and generate key id of both the projects.
Image3



Image4
Image5
Image7
4- Create an andorid project and select google Map Activity (we are using Android Studio)
5- Add your Google API key to the srting.xml file
6- Make sure to add latest gms:play-services i nandroid studio as shown below.
Go to File -> Project Structure
Select 'Project Settings'
Select 'Dependencies' Tab
Click '+' and select '1.Library Dependencies'
Search for : com.google.android.gms:play-services
Select the latest version and click 'OK'
7- Run the application
- If you get below error
application won't run unless you update google play service
make sure to follow belwo steps
SDK Manager => Extras => Google Play Services.
Image6

Note: Make sure you change your API_KEY inside both google_maps_api.xml and strings.xml
- If you get this error java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException
add below line in build.gradle inside defaultConfig{}
multiDexEnabled true
Image8

No comments: