生活在远方

是的,因为真正的生活是在远方

An Android application with map

Written By: tr - Apr• 04•10

I had read a few tutorials on how to develop an Android appication with map display. Today I had actually built one. I would like to summarize the key points/steps in making this application work.

1. First of all, get an Android Map API Key from Google.

This actually involves two steps.

Firstly, you will have to create a key store to sign your Android application. This is quite easy and straightforward.

Secondly, apply an Android Map Key from Google: http://code.google.com/intl/zh-CN/android/maps-api-signup.html. To make this work, you have to know where is your key store file is located (as created in the above step) and also have the JDK tool named keytool. From the command line, type:

   keytool -list -keystore the-path-to-your-key-store-file

It will prompt you to enter the password to the key store and will generate a MD5 finger print for this particular key store file. Copy this MD5 finger print to the above URI and Google will give you the Android Map API Key immediately. It is strongly suggested to save this Key information.

2. Create an Android application.

Note: It must be created with target set to: “Google APIs”. You should not set the application target to “Android x.x” or it will not be running properly.

Note: The target of the AVD that runs the map application must also be set to “Google APIs”.

The coding of the application is actually quite simple. There are only two points to be highlighted:

1. The application must be granted ACCESS_FINE_LOCATION and ACCESS_INTERNET permissions;

2. The mapview controll used in the view must be provided with the API key generated in Step 1. It will look something like this:

<com.google.android.maps.MapView
   android:id="@+id/myMapView"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:enabled="true"
   android:clickable="true"
   android:apiKey="your api key here"
/>

With these settings, the map application can eventually run successfully. However, in my implementation, the map shown in my AVD is only grids, no actuall maps at all. But in real machine (mine is Nexus One), the application is running correctly.

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">