Since Google's entry into China in, the development speed in the map and mobile fields is basically several times the annual growth. Developing related applications on the latest Android platform will be of great help to our android development if we have a deep understanding of Google map. the following is my summary of Google map in Android development.
1. First, obtain your debug keystore location:
Open eclipse ---> Windows ---> preferences ---> Android ---> build
Check the default debug keystore location. my options are C:/Documents and Settings/sdhbk/. Android/debug. keystore.
2. Locate the bin directory of the Java installation directory under CMD and type the following command:
Keytool-list-alias androiddebugkey-keysto
Re "C:/Documents and Settings/sdhbk/. Android/debug. keystore"-storepass android
-Keypass android
Androiddebugkey, 2009-7-25, privatekeyentry,
Authentication fingerprint (MD5): da: D5: 6e: C2: 80: D1: 0f: 0d: F8: 2a: 58: 6a: 74: 7c: Ce: 2D
3.
Open http://code.google.com/intl/zh-CN/android/maps-api-signup.html
Enter your authentication fingerprint (MD5) to obtain the apikey. The result is as follows:
Thank you for registering the android map API key!
Your key is:
Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
4. Use the obtained apikey:
Add mapview to layout
Or
5. android provides a map extension library COM. google. android. maps, you can use it to add powerful map functions to your android application. This library is located in Your-SDK_DIR/add-ons/google_apis-3/libs.
You must set full permissions in manifest. XML, such:
Add the Map Library to be used in manifest. xml:
...
...
...
It should be noted that this library is not the standard Android SDK content, you can also download it from here and put it in your SDK.
Map Library Analysis
Maps Library provides a dozen classes, specific can refer to here http://code.google.com/intl/ja/android/add-ons/google-apis/reference/index.html, including mapview, mapcontroller, mapactivity and so on.
Mapview is used to display the view of a map. It is also derived from Android. View. viewgroup.
Maps can be displayed in different forms, such as street view mode and satellite mode. For details, refer:
Setsatellite (Boolean), settraffic (Boolean), and setstreetview (Boolean)
Mapview can only be created by mapactivity. This is because mapview needs to be connected to the network or file system through background threads, which must be managed by mapactivity.
In Android 1.5, map zoom adopts the built-in mechanism. You can use setbuiltinzoomcontrols (Boolean) to set whether to display the zoom control on the map.
Mapactivity is an abstract class. Any activity that wants to display mapview must be derived from mapactivity. You must create a mapview instance in oncreate () of its derived class. You can use mapview Constructor (then add it to a Layout View with viewgroup. addview (View) or layout XML.
Instance analysis
Finally, we will use a small program to demonstrate the development of the map function in Android. The main function is to scale the map and add a menu so that you can manually select the display mode of the map.
Step 1: Create an android project. Note that the build target to be selected here is "Google APIs"
Step 2: Modify the menifest file:
Step 3: Modify the layout file, Main. xml
Here, you need to set ???????????? Changed to the API key you applied.
Step 4: modify the code:
Package com. Map. prac;
Import com. Google. Android. Maps. geopoint;
Import com. Google. Android. Maps. mapactivity;
Import com. Google. Android. Maps. mapcontroller;
Import com. Google. Android. Maps. mapview;
Import Android. App. alertdialog;
Import Android. App. Dialog;
Import Android. content. dialoginterface;
Import Android. OS. Bundle;
Import Android. util. log;
Import Android. View. keyevent;
Import Android. View. Menu;
Import Android. View. menuitem;
Public class mapviewprac2 extends mapactivity {
Private final string tag = "mapprac ";
Private mapview = NULL;
Private mapcontroller MC;
// Menu items
Final private int menumode = menu. first;
Final private int menuexit = menu. First + 1;
Final private int menucommandlist = menu. First + 2;
Private int chooseitem = 0;
/** 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. Map );
MC = mapview. getcontroller ();
Mapview. settraffic (true );//
Mapview. setsatellite (false );
Mapview. setstreetview (true );
// Geopoint Gp = new geopoint (INT) (39.269259*1000000), (INT) (115.255762*1000000); // Yixian
Geopoint Gp = new geopoint (INT) (39.95*1000000), (INT) (116.37*1000000); // Beijing
// MC. animateto (GP );
// MC. setzoom (12 );
MC. setcenter (GP );
// To display zoom control in mapview
Mapview. setbuiltinzoomcontrols (true );
}
@ Override
Public Boolean onkeydown (INT keycode, keyevent event ){
// Todo auto-generated method stub
Log. I (TAG, "Enter onkeydown ");
Return super. onkeydown (keycode, event );
}
@ Override
Public Boolean oncreateoptionsmenu (menu ){
Menu. Add (0, menumode, 0, "map mode ");
Menu. Add (0, menucommandlist, 1, "command List ");
Menu. Add (0, menuexit, 2, "exit ");
Return super. oncreateoptionsmenu (menu );
}
@ Override
Public Boolean onmenuitemselected (INT featureid, menuitem item ){
// Todo auto-generated method stub
Switch (item. getitemid ())
{
Case menumode:
Dialog dmode = new alertdialog. Builder (this)
//. Seticon (R. drawable. alert_dialog_icon)
. Settitle (R. String. alert_dialog_single_choice)
. Setsinglechoiceitems (R. array. select_dialog_items2, chooseitem, new dialoginterface. onclicklistener (){
Public void onclick (dialoginterface dialog, int whichbutton ){
Log. I (TAG, "Choose button is" + whichbutton );
Chooseitem = whichbutton;
/* User clicked on a radio button do some stuff */
}
})
. Setpositivebutton (R. String. alert_dialog_ OK, new dialoginterface. onclicklistener (){
Public void onclick (dialoginterface dialog, int whichbutton ){
/* User clicked yes so do some stuff */
Log. I (TAG, "item =" + chooseitem );
Switch (chooseitem)
{
Case 0:
Mapview. setsatellite (false );
Break;
Case 1:
Mapview. setsatellite (true );
Break;
Case 2:
Mapview. settraffic (true );
Break;
Case 3:
Mapview. setstreetview (true );
Break;
Default:
Break;
}
}
})
. Setnegativebutton (R. String. alert_dialog_cancel, new dialoginterface. onclicklistener (){
Public void onclick (dialoginterface dialog, int whichbutton ){
/* User clicked no so do some stuff */
}
})
. Create ();
Dmode. Show ();
Break;
Case menucommandlist:
// Create the Dialog
Dialog d = new alertdialog. Builder (this)
. Settitle (R. String. select_dialog)
. Setitems (R. array. select_dialog_items, new dialoginterface. onclicklistener (){
Public void onclick (dialoginterface dialog, int which ){
/* User clicked so do some stuff */
String [] items = getresources (). getstringarray (R. array. select_dialog_items );
/* New alertdialog. Builder (this)
. Setmessage ("You selected:" + which + "," + items [which])
. Show ();*/
Log. I (TAG, "you choose is:" + items [which]);
}
})
. Create ();
// Show the Dialog
D. Show ();
Break;
Case menuexit:
Finish ();
Break;
Default:
Break;
}
Return super. onmenuitemselected (featureid, item );
}
@ Override
Protected Boolean isroutedisplayed (){
// Todo auto-generated method stub
Return false;
}
}
The usage of Google map remains to be summarized by Android Developers in actual development!