Google Provides an API to work with google maps. This API is available for update through your android sdk manager. To access the google map in your application you have to register and obtain a Map API key. Even for testing google map in emulator you need this key.
Download the Google API.
Select the Google APIs by Google Inc. option and click on Install pac button.
Create a Emulator for running this google map. It doesn’t run in your default Emulators, to run a Map application you need a emulator which supports google map. To create a emulator open AVD Manager.
- Type a name for your emulator
- Select the target as Google API
- Specify the SD Card size.
- Click on Create AVD button.
See bellow the emulator with name which you specified is ready.
Now you have to generate a MD5 finger print for registering yourself with google for using its google map data.
To generate MD5 you have to use keytool, this tool takes keystore as argument and generates MD5 finger print. This MD5 finger print is necessary to get the map API key.
For Ubuntu users keystore is present in .android folder which is located in your home directory.
- press ctrl+alt+t
- Enter su and then your root password
- Type: keytool -list -alias androiddebugkey -keystore /home/ethics/.android/debug.keystore -storepass android -keypass android
in my case ethics is my user name.
androiddebugkey, Jul 1, 2011, PrivateKeyEntry,Certificate fingerprint (MD5): 55:EB:52:76:EE:11:3C:B7:90:1D:DF:6A:98:A0:32:0C
Note : .android will be a hidden file so press ctrl+h in your home directory to see it.
Copy this 55:EB:52:76:EE:11:3C:B7:90:1D:DF:6A:98:A0:32:0C and paste it in My certificate’s MD5 fingerprint edit box in this link . Now you will get an API key as an output. Copy the generated API key, this will be used in your Project.
Now go to eclipse and open a new project selecting Google APIs
Then edit the java file as bellow:
- MapActivity is a class from com.google.android.maps which helps you to use map related operations.
- isRouteDisplayed() is its override method so include that.
Alter your manifest file in the same order as mentioned bellow:
- Since google maps library doesn’t belong to Android API you need to give library permission.
- Google map uses Internet so you have to add Internet permission too.
NOTE: Place it in the same order as mentioned bellow
Your Xml file has to be edited as bellow:
- com.google.android.maps.MapView is a widget just like other views in android.
- API key which you obtained from this site must be pasted under android:apiKey attribute.
Your final output:
That’s it we are done. Now you will be able to access the google map from your application.
Never miss place the tags in Manifest file it will create problem.
In case of any error look at this sites: