Android Tech

The more we share, the more we get

Google Map (Part 1) – How to show a Google Map on Android application

This post will guide you how to show a Google Map on an Android application (AVD target name is Google APIs using Eclipse).

First of all, we must allow Android application to access the Internet to get map data. So, we will customize the AndroidManifest.xml as follow:

1. Open the AndroidManifest.xml in following dir:

This is the default screen when you open this file, it not viewed in XML.

2. After that, we choose tab Permission as follow:

3. Click Add button to add a new permission type

4. New popup window appear as follow, choose Uses permission and then click OK:

Here is the result

5. Set the Attributes for Uses Permission to access the Internet

6. Left click on the item in Permissions area to make it update

7. To use GPS functions, you have to add one more permission is ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION

That’s all for the UI of AndroidManifest.xml file.

8. Now we continue with the xml view of this file. It’s as follow image:

We have to define the library used for Google APIs. Insert the following code in tag “Application” (if not, it doesn’t work):

<uses-library android:name=”” />

9. Go on, we modify the main.xml to show the map on your application. We have to put a View on it. Open the mail.xml in this directory:

10. The default view of this file the same as the AndroidManifest.xml (not xml text view), so we switch it to xml text view:

Here is the default content

11. We replace the TextView control of Android by MapView control supported by Google

12. We must generate a Google API key and insert to this file for finishing update main.xml file. To do this, go to directory formatted as follow:

C:\Documents and Settings\<user name>\.android

and copy debug.keystore file to another place for convenience to use. For example is D:\Work\Android\Tools

13. Open command prompt and move to folder bin where JDK installed

14. Use this command to get the MD5 string from keytool.exe tool:

keytool.exe -list -alias androiddebugkey -keystore <Path_To_KeyStore>\debug.keystore -storepass android -keypass android

This is the result with MD5 code:

15. Copy this code by right click on the command window and choose Mark

16. Mark the string

17. Copy this code by left click on it

18. Go to Google Map site:

19. Paste this code and submit to get the API keys

Here is the API keys returned

20. Copy this code and paste to main.xml file

21. Go to Java source code and modify it to display the map in following directory

This is the default code:

22. Replace the import from Activity of Android to MapActivity of Google and the extends from Activity to MapActivity. Insert the method isRouteDisplayed required by Google

Press Ctrl + F11 to run, the final result like this:

In case your environment use proxy, you should choose “Run configurations…”

A configuration window will appear, input the proxy name after string “-http-proxy” (this string have to be kept), and choose the virtual device to run with (this virtual device must have target name is Google APIs) as follow:


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: