In the use of Baidu map in Android, we can first look at the corresponding SDK information Baidu map: HTTP://DEVELOPER.BAIDU.COM/MAP/INDEX.PHP?TITLE=ANDROIDSDK, It's basically about all the configuration in Android, API calls and other operations, let's take a look at the Baidu map in the Android environment to build the steps: We use the Baidu map version is
Android SDK v3.1.1, different version, the inside of the API may not be the same, so I hope you can pay attention!!
First, the application of the key, whether it is the development of Google Maps or Baidu map we all need to apply for a key, of course, we have to register before the application of Baidu users, otherwise is not the application, the key of the Android version of the application steps: http://developer.baidu.com/map/ Index.php?title=androidsdk/guide/key, note that the security code in the configuration can not be filled out, otherwise you will not see the map and a series of problems, security code must be the whole code of the composition of the rule: Android Signing certificate SHA1 value + " ;” +packagename (i.e.: digital signature + semicolon + package name), about the SHA1 signature certificate of the value of the acquisition, there is a corresponding operation method, fill out the corresponding information, there will be a corresponding 24-bit AK, is our key, we have to record it down;
Second, download the Android version of Baidu map sdk:http://developer.baidu.com/map/index.php?title=androidsdk/sdkandev-download, recommended download all, including the development package , documents, and samples can also be downloaded from my blog resources: http://download.csdn.net/detail/harderxin/8002031;
Third, the new Android project, will download the Libs package file into the project, which Baidumapapi_v3_1_1.jar said the development of Baidu map must use the package, while Liblocsdk3.so and locsdk_3.1. The jar is for Baidu to locate the resources used by the SDK, and developers can add their own according to their needs. Introduce its jar package into project engineering, and copy the project package such as:
Iv. Open the Androidmainifest.xml file for our project and put the key we obtained above into the meta information under application:
<application> <meta-data android:name= "Com.baidu.lbsapi.API_KEY" android:value= "developer KEY"/ > </application>
Add Baidu related rights in Androidmainifest.xml:
<uses-permission android:name= "Android.permission.GET_ACCOUNTS"/> <uses-permission android:name= " Android.permission.USE_CREDENTIALS "/> <uses-permission android:name=" Android.permission.MANAGE_ACCOUNTS "/ > <uses-permission android:name= "Android.permission.AUTHENTICATE_ACCOUNTS"/> <uses-permission android: Name= "Android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name= " Android.permission.INTERNET "/> <uses-permission android:name=" com.android.launcher.permission.READ_ SETTINGS "/> <uses-permission android:name=" Android.permission.CHANGE_WIFI_STATE "/> <uses-permission Android:name= "Android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name= " Android.permission.READ_PHONE_STATE "/> <uses-permission android:name=" android.permission.WRITE_EXTERNAL_ STORAGE "/> <uses-permission android:name=" Android.permission.BROADCAST_STICKY "/> <uses-permission Android:name= "Android.permissioN.write_settings "/> <uses-permission android:name=" Android.permission.READ_PHONE_STATE "/>
to add support for a screen:
<supports-screens android:anydensity= "true" android:largescreens= "true" android:normalscreens= " False " android:resizeable=" true " android:smallscreens=" true "/>
Five, add Baidu Map display control in Main.xml:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" fill_parent " android:layout_height=" fill_parent " android:o rientation= "vertical" > <com.baidu.mapapi.map.mapview android:id= "@+id/bmapview" android: Layout_width= "Fill_parent" android:layout_height= "fill_parent" android:clickable= "true"/></ Linearlayout>
six, the introduction of Baidu Map API in Mainactivity, write the relevant code:
Package Com.xin.activity;import Android.app.activity;import Android.os.bundle;import Com.baidu.mapapi.sdkinitializer;import Com.baidu.mapapi.map.baidumap;import Com.baidu.mapapi.map.mapview;public Class Mainactivity extends Activity {private Mapview Mmapview = Null;private baidumap baidumap; @Overrideprotected void OnC Reate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);//Initialize the context information before using each component of the SDK, Incoming applicationcontext//Note that this method is to be implemented before Setcontentview method Sdkinitializer.initialize (Getapplicationcontext ()); Setcontentview (R.layout.main);//Get map Control Reference Mmapview = (Mapview) Findviewbyid (R.id.bmapview); baidumap=mmapview.getmap ();//Set the map type to normal map//baidumap.setmaptype (baidumap.map_type_normal);//set map type to satellite map//baidumap.setmaptype ( Baidumap.map_type_satellite);//Open Traffic map baidumap.settrafficenabled (true);} @Overrideprotected void OnDestroy () {Super.ondestroy ();//Mmapview.ondestroy () is executed when activity executes OnDestroy, Implement Map Lifecycle Management Mmapview.ondestroy ();} @Overrideprotected void Onresume () {super.onresume ();//In Activity executionExecutes Mmapview when Onresume. Onresume (), Implementing Map Lifecycle Management Mmapview.onresume ();} @Overrideprotected void OnPause () {super.onpause ();//Mmapview is executed when activity executes OnPause. OnPause (), Implement Map Lifecycle Management Mmapview.onpause ();} <span style= "FONT-SIZE:18PX;" >}</span>
Seven, the operation of the project, in our simulator appears on the map display, that is, the environment to build success!!
I control the display traffic map in the code: baidumap.settrafficenabled (TRUE); So the effect will appear, Baidu inside provides a lot of API for our reference, such as labeling, covering, bus inquiries and other information, We can according to their own needs to write the relevant code, where the environment to build only played a role, the future expansion, but also according to the project needs to design their own implementation:
Baidu Online api:http://wiki.lbsyun.baidu.com/cms/androidsdk/doc/v3_1_1/
Baidu Basic Map: Http://developer.baidu.com/map/index.php?title=androidsdk/guide/basicmap
Android Tour 1800-degree map environment construction