PS: (1. Map application must be tested in real machine;
2.Design by:android Stdio;
3. Baidu Map Official Reference link ( HTTP://DEVELOPER.BAIDU.COM/MAP/INDEX.PHP?TITLE=ANDROIDSDK );
4. If there are deficiencies, please indicate, thank you);
Here we study Baidu map:
"1" First: In the use of Baidu map when you need to get the official Baidu map AK Code, specifically how to obtain, please refer to (http://developer.baidu.com/map/index.php?title= Androidsdk/guide/key)
"2" will need to download the AK code after the official Baidu jar package and so file, for details, please refer to (http://lbsyun.baidu.com/sdk/download?selected=mapsdk_basicmap,mapsdk _searchfunction,mapsdk_lbscloudsearch,mapsdk_calculationtool)
"3" gets the jar package as well as the so file that needs to be loaded in the project:
How Eclipse is loaded
------------------------------------------------Ornate Split Line---------------------------------------
The gadget used by Android Stdio is written, so tell me about the load jar package and so files for as:
"Add jar Package"-in positive view, the corresponding jar package should first be placed in the project's Libs folder, and then need to add this statement under this item:, otherwise your jar package will not be able to use
"Add so File"-small series according to the collection of data, found that there is such a method, tested available, this method originated from the foreign Kyle thielk Blog
Create the jinlibsunder the main folder and copy the Armeabi to this folder
"4" Add encryption Key configuration permissions
(Add encryption Key)
(Configure permissions)
Above code reference (http://developer.baidu.com/map/index.php?title=androidsdk/guide/hellobaidumap)
"5" Add XML layout file
1 <Com.baidu.mapapi.map.MapView2 android:id= "@+id/bmapview"3 android: Layout_width= "Fill_parent"4 android:layout_height= "Fill_parent"5 android: Clickable= "true"/>
"6" Write java Code (code implementation "1. Create a map, 2. Display a satellite map, 3. Show Live Traffic")
1 Public classMainactivityextendsactionbaractivity {2 PrivateMapview mapview=NULL;3 PrivateBaidumap mbaidumap=NULL;4 @Override5 protected voidonCreate (Bundle savedinstancestate) {6 Super. OnCreate (savedinstancestate);7 /*8 * Note the use of SDK components before initializing the context information, incoming ApplicationContext9 * Note that this method is to be implemented before SetcontentviewTen */ One sdkinitializer.initialize (Getapplicationcontext ()); A Setcontentview (r.layout.activity_main); - Initview (); - the } - - Private voidInitview () { -mapview=(Mapview) Findviewbyid (R.id.bmapview); +Mbaidumap=mapview.getmap ();//get the map from the container -Mapstatusupdate msu= Mapstatusupdatefactory.zoomto (15.0f);//set the starting ruler for a map + Mbaidumap.setmapstatus (MSU); A } at - @Override - protected voidOnDestroy () { - Super. OnDestroy (); - Mapview.ondestroy (); - } in - @Override to protected voidOnresume () { + Super. Onresume (); - Mapview.onresume (); the } * $ @OverridePanax Notoginseng protected voidOnPause () { - Super. OnPause (); the mapview.onpause (); + } A the /* + * Context Menu - */ $ @Override $ Public BooleanOncreateoptionsmenu (Menu menu) { - //inflate the menu; This adds items to the action bar if it is present. - getmenuinflater (). Inflate (R.menu.menu_main, menu); the return true; - }Wuyi /* the * Click events for the Replication menu option - */ Wu @Override - Public Booleanonoptionsitemselected (MenuItem item) { About Switch(Item.getitemid ()) $ { - CaseR.id.id_map_common: - Mbaidumap.setmaptype (baidumap.map_type_normal); - Break; A CaseR.id.id_map_site: + Mbaidumap.setmaptype (baidumap.map_type_satellite); the Break; - Caser.id.id_map_traffic: $ if(mbaidumap.istrafficenabled ()) { theMbaidumap.settrafficenabled (false); theItem.settitle ("Real-time traffic (OFF)"); the}Else the { -Mbaidumap.settrafficenabled (true); inItem.settitle ("Live Traffic (ON)"); the } the Break; About } the the return Super. onoptionsitemselected (item); the } +}
"7" Writing Menu_main.xml
<ItemAndroid:id= "@+id/id_map_common"Android:title= "@string/map_common"app:showasaction= "Never" /> <ItemAndroid:id= "@+id/id_map_site"Android:title= "@string/map_site"app:showasaction= "Never" /> <ItemAndroid:id= "@+id/id_map_traffic"Android:title= "@string/map_traffic"app:showasaction= "Never" />
"8" writing string.xml
<stringname= "Map_common">General Map</string> <stringname= "Map_site">Satellite map</string> <stringname= "Map_traffic">Real-time Traffic (OFF)</string>
"9" project completed, as follows:
Baidu Map Learning (Ⅰ)-android-side map display and simple application