How simple is it? Look, it just shows the map:
If you want to write an android Google map application, it is more difficult to prepare it than to write other applications. Because:
- The android Google map API is not open-source and free. It is Google's private software, although it is free;
- This API is always dependent on downloading map information from Google.
The first article is easy to handle. I am using android 2.1. Other versions, such as 1.5, need to be similar. Google map api needs to be imported into the project, which is not available by default. By default, a version of android, such as android 2.1, needs to be changed to the corresponding version of google apis. The version must be consistent with that of android. This google apis is an android superset of the same version, including google's private app api. For example:
In this way, you can use the following in the project:
Com. google. android. maps. MapActivity
This is not enough. google needs a signature fingerprint mechanism. It must first register with google and include this fingerprint in the application before downloading the map information. That is to say, the fingerprint information should be carried in each download of the MAP information.
Registration and retrieval of fingerprint information are free of charge.
There are two types of fingerprints:
- The debug fingerprint used for development can only be used in your own debug application;
- Official fingerprint.
You only need the first one.
The procedure is: first, the development environment should have JDK. Go to the bin directory of JDK and run:
The following code is displayed:
Copy the fingerprint part.
Then visit:
Http://code.google.com/intl/zh-CN/android/add-ons/google-apis/maps-api-signup.html
There is also a premise that you have to have a google account and log on.
Copy the md5 fingerprint to the red box:
Select agree to the agreement.
After submission, you will see:
In fact, it is mainly to get the key in the red box. In the program or layout file, add or set the androidLapiKey attribute where MapView is used.
The code is actually very simple:
Public class LocationActivity extends MapActivity {
Private MapView mapView;
Private MapController mapController;
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
MapView = (MapView) findViewById (R. id. map_view );
Log. I ("welcome", "created map activity .");
}
@ Override
Protected boolean isRouteDisplayed (){
Return false;
}
}
Layout file used:
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical" android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<Com. google. android. maps. MapView
Android: id = "@ + id/map_view" android: layout_width = "fill_parent"
Android: layout_height = "fill_parent" android: enabled = "true"
Android: clickable = "true" android: apiKey = "xxxxxxxxxxxxxx"/>
</LinearLayout>
From the treasure Valley