Before also contacted the development of Baidu map, but that is on the Internet to find the case or code, but also the older version. Plan to re-learn the development of Baidu map.
The version of the Baidu map used for this time is
Android SDK v3.0.0
This article mainly describes the map development of Baidu preparation and map of the successful display can be.
First of all, we recommend that you register for a Baidu account first.
Application key (to achieve Baidu map of the relevant services must apply for the key), website: http://lbsyun.baidu.com/apiconsole/key
Note that the application name should not be duplicated or invalid, the input details of the security code can be viewed: http://developer.baidu.com/map/sdkandev-14.htm
When the app is created successfully, a key is returned (AK is the key):
OK, at this point, the development preparation is basically complete. (Download the SDK without saying it, choose the features you need.) Website: http://developer.baidu.com/map/sdkandev-download.htm)
The next step is to achieve the most basic display of the map on the phone.
project Configuration
The first step: Create a new Libs folder in the project, copy the Baidulbs_android.jar in the development package to the Libs root directory, copy libbaidumapsdk_vx_x_x.so to Libs\ Armeabi Directory (the official website has already had these two files, if you want to integrate into your project, you need to add it), copy the completed project catalog as shown;
Note: Other resources used, developers can add their own according to the actual needs.
The second step: select "Add External JARs" in the project properties->java Build path->libraries, choose Baidumapapi_vx_x_x.jar, and return when determined.
With the above two steps, you will be able to use the Baidu Map SDK to provide you with all the functions.
Note: Because of the ADT plugin upgrade, if you are using Eclipse ADT 22, you need to set the development environment accordingly, as follows:
1. Select project in Eclipse, right-click Properties->java Build path->order and Export to make Android Private libraries tick;
2. Project-clean-> Clean All
(Note: If you're running the Times wrong: Unable to execute dex:multiple Dex files define lcom/baidu/mapapi/xxxx or Conversion to Dalvik for Mat failed:unable to execute dex:multiple Dex files define LCOM/BAIDU/MAPAPI/XXXXX do not perform the above configuration. Because the external file is checked repeatedly, uncheck and then clean.
Show Baidu Map
The next step is to start with the code.
Baidu Map SDK for developers to provide a convenient display of Baidu map data interface, through the following steps, you can use the Baidu map data in your application:
The first step: Create and configure the project (see the Project configuration section for details);
The second step: Add the development key, the required permission and other information in the androidmanifest;
(1) Add a development key in application
< Application <meta-data android:name= "Com.baidu.lbsapi.API_KEY" android:value= " Developer Key "/> </application>
(2) Add the required permissions
<uses-permissionAndroid:name= "Android.permission.GET_ACCOUNTS" /> <uses-permissionAndroid:name= "Android.permission.USE_CREDENTIALS" /> <uses-permissionAndroid:name= "Android.permission.MANAGE_ACCOUNTS" /> <uses-permissionAndroid:name= "Android.permission.AUTHENTICATE_ACCOUNTS" /> <uses-permissionAndroid:name= "Android.permission.ACCESS_NETWORK_STATE" /> <uses-permissionAndroid:name= "Android.permission.INTERNET" /> <uses-permissionAndroid:name= "Com.android.launcher.permission.READ_SETTINGS" /> <uses-permissionAndroid:name= "Android.permission.CHANGE_WIFI_STATE" /> <uses-permissionAndroid:name= "Android.permission.ACCESS_WIFI_STATE" /> <uses-permissionAndroid:name= "Android.permission.READ_PHONE_STATE" /> <uses-permissionAndroid:name= "Android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permissionAndroid:name= "Android.permission.BROADCAST_STICKY" /> <uses-permissionAndroid:name= "Android.permission.WRITE_SETTINGS" /> <uses-permissionAndroid:name= "Android.permission.READ_PHONE_STATE" />
(3) Adding a map control in the layout XML file
< Com.baidu.mapapi.map.MapView Android:id = "@+id/bmapview" android:layout_width= "Fill_parent" android:layout_height= "Fill_parent " android:clickable=" true "/>
(4) Initializes the context global variables referenced by the SDK when the application is created:
Public class extends Activity { @Override protectedvoid onCreate (Bundle savedinstancestate) { Super . OnCreate (savedinstancestate); // initializes the context information before using each component of the SDK, passing in the ApplicationContext // Note that this method should be implemented before setcontentview the method sdkinitializer.initialize (Getapplicationcontext ()); Setcontentview (R.layout.activity_main); } }
Note: Before each functional component of the SDK is used, you need to call
Sdkinitializer.initialize (Getapplicationcontext ()), so we recommend that the method be placed in the application initialization method
(5) Create map activity to manage map life cycle
Public classMainactivityextendsActivity {mapview Mmapview=NULL; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); //initializes the context information before using each component of the SDK, passing in the ApplicationContext//Note that this method should be implemented before setcontentview the methodsdkinitializer.initialize (Getapplicationcontext ()); Setcontentview (R.layout.activity_main); //Get map Control ReferenceMmapview =(Mapview) Findviewbyid (R.id.bmapview); } @Overrideprotected voidOnDestroy () {Super. OnDestroy (); //Implement Mmapview.ondestroy () when activity executes OnDestroy to achieve map life cycle managementMmapview.ondestroy (); } @Overrideprotected voidOnresume () {Super. Onresume (); //perform mmapview. Onresume () When activity executes Onresume, enabling map Lifecycle managementMmapview.onresume (); } @Overrideprotected voidOnPause () {Super. OnPause (); //perform mmapview. OnPause () When activity executes OnPause, enabling map Lifecycle managementMmapview.onpause (); } }
After completing the above steps, run the program to display the following map in your app:
This article is almost the same as Baidu's first case (Hello baidumap), only add the LZ's personal experience of the simple description.
Demo Download: http://download.csdn.net/detail/af74776/7714789