I. Preparations
1. Apply for the Android Map API Key
Prerequisites: Your google account and System Certificate.
First find our debug. keystore file. If you have installed eclipse and configured the android development environment (the Environment configuration is no longer repeated here, the previous blog provides detailed instructions ), you can use Window-> Preference-> Android-> Build. We can see that the Default debug keystore is debug. the keystore path.
Next we need to obtain the MD5 value, open the command line, and go to debug. in the directory where the keystore is located, run the command keytool-list-keystore debug. keystore. Here, you will be asked to enter the keystore password. The default value is android.
Next, we need to apply for the Android Map API Key and open the URL "primary Key.
1. Create an AVD Based on Google APIs
Window-> AVD Manager-> new, enter the AVD name, and select Google APIs in Target.
Note that if the Target option does not contain the Google APIs option, install Google APIs in the Android SDK Manager.
1. Create a simple GoogleAPIs-based application
1. Create a new project
Just like creating a common android app, File-> new-> other-> Android Project. we name the Project googleMapApp. Note that, select Google APIs when selecting Target.
1. Necessary modifications
Open the AndroidManifest. xml file. To use Google Map APIs, you must define the following sentence:
<Uses-libraryandroid: name = "com. google. android. maps"/>
Because we still need to use the network, we need to add a network access license <uses-permissionandroid: name = "android. permission. INTERNET "/>, if you do not add a network license, the application will not display a map, only display grid lines.
The following code adds the MapView attribute to the layout file main. xml:
[Html] <com. google. android. maps. MapView
Android: id = "@ + id/mapView"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: apiKey = "0DXjJ7k6Ul6gx2s4aQEbs8Chg43eW-dVeowPqIQ"
/>
<Com. google. android. maps. MapView
Android: id = "@ + id/mapView"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: apiKey = "0DXjJ7k6Ul6gx2s4aQEbs8Chg43eW-dVeowPqIQ"
/>
Android: apiKey indicates the API Key generated by MD5 when logging on to the google account. Do not confuse it with MD5 here!
GoogleMapAppActivity must inherit MapActivity rather than Activity. The Code is as follows:
[Java] public class GoogleMapAppActivity extends MapActivity {
Public MapView mapView;
Public MapController mapController;
Public GeoPoint geoPoint;
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
MapView = (MapView) findViewById (R. id. mapView );
MapView. setTraffic (true); // set it to traffic mode
MapView. setClickable (true );
MapView. setBuiltInZoomControls (true); // You can scale the settings.
MapController = mapView. getController ();
GeoPoint = new GeoPoint (int) 40.38014*1000000, (int) 117.00021*1000000); // set the starting point to be near Beijing
MapController. animateTo (geoPoint); // go to Beijing
MapController. setZoom (12 );
}
@ Override
Protected boolean isRouteDisplayed (){
Return false;
}
From pku_android