How to Display Google Map in Android
Hi Everyone,
In this Blog Post I am going to brief about, How to display Google Map in Android.
Let’s see how to display the Google Map in Android.
Step 1:
Login to your Gmail Account. and go to Google Developer Console(https://console.developers.google.com). Next, Select APIs & auth Tab in left panel. Then Select APIs. And search for “Google Maps Android API v2“, then Enable it.
See bellow image
Step 2:
Now, You have to generate API key to access the Google Map. For that, go to this link: – https://console.developers.google.com/project/1005302408584/apiui/credential
Then Click Create new Key Button under Credential tab.
To get a One SHA1 Certificate Fingerprint:
Simple way to get certificate fingerprint is right click your project Android Tools ->Export Signed Application Pakage -> Next (Other Way to get Certificate Fingetprint – Certificate Fingetprint)
Use Existing Key Store(If you dont have Keystore, Go with Create New Keystore), then Enter your Keystore Password click Next
Now, You can see Certificate Fingerprint. Just copy that, and enter the Certificate Fingerprint in Console. Then append your package name with comma.
For Example:
45:B5:E4:6F:36:AD:0A:98:94:B4:02:66:2B:12:17:F2:56:26:A0:E0;com.example.YourPackageName
Now Click Create. You created the API Key to access the Google Map. Save this Key for future.
Step 3:
Create a new project. Make sure you have installed Google Play Service Library in Android SDK Manager(Windows->Android SDK Manager->Extras).
Then Import Google Play Service Library Project from the following path:
Your sdk folder/sdk/extras/google/google_play_sevices/libproject/google-play-services_lib/
Now add the library project to your Android project(Right your project ->Build Path -> Configure Build Path -> Android -> Click Add – > Select google-play-services_lib -> OK).
Step 4:
Creare map.xml in res/layout/map.xml. Now Paste the folowing code.
<?xml version="1.0" encoding="utf-8"?> <fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" android:name="com.google.android.gms.maps.MapFragment"/>
Step 4:
Create MainActivity.java in src/yourpakagename/MainActivity.java. Now Paste the following code.
package com.example.clixoomap; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.LatLng; public class MainActivity extends Activity { GoogleMap googleMap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.map); try { if (googleMap == null) { googleMap = ((MapFragment) getFragmentManager(). findFragmentById(R.id.map)).getMap(); } } catch (Exception e) { e.printStackTrace(); } } }
Step 5:
Manifest.xml
Replace “YourAppKey” with your API Key.
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.clixoomap" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" /> <permission android:name="com.example.googlemaps.permission.MAPS_RECEIVE" android:protectionLevel="signature" /> <uses-permission android:name="com.example.googlemaps.permission.MAPS_RECEIVE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-feature android:glEsVersion="0x00020000" android:required="true" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <activity android:name="com.example.map.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="YourAppKey" /> </application> </manifest>
Run your Application and get the Google Map(See Image Bellow).
I hope this blog post was helpful. Do let me know your feedback.
Related Posts
Nithya Govind
Latest posts by Nithya Govind (see all)
- Padlock It can do Correlation Diamonds Port ᗎ Perform On line & Zero cost - July 8, 2022
- A good Overview Of The 100 Lucky Bee Nexgen Texas hold’em Computer chip Set - September 2, 2021
- How to Display Image Gallery Using ViewPager in Android - April 12, 2015