In this article, we'll explore the SDK for integrating Baidu maps into Android apps, as well as creating a simple example project.
One, Baidu map Android SDK Integration
1. Enter Baidu Map Developer website: http://lbsyun.baidu.com/index.php?title=androidsdk
2. Click on the "Get Key" menu on the left to request a key for the app. The key I'm applying for here is: VF4KXBWL1MEVOYCFSML4YRLGPYZ99XYF
3, after the application to return to the above mentioned website, click on the left: "Related download" menu, download Baidu Map of the Android SDK. Currently the latest SDK version is v3.7.3.
4, a new demo project, the development package of Baidumapapi_base_v3_7_3.jar and other 6 jar file copy libs root directory, the Armeabi copy to the Libs directory.
The second step: in the project Properties->java Build path->libraries Select "Add External JARs", Selected Baidumapapi_base_v3_7_3.jar and other 6 jar files, determined to return.
With the above two steps, you will be able to use the Baidu Map SDK to provide you with all the functions.
Second, create a simple display map of the demo
1. Create a new Baidu map component in Activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" ><com.baidu.mapapi.map.MapView android:id="@+id/bmapView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" /></LinearLayout>
2, in the Androidmanifest, configure the Baidu map developer key and the required permissions
<?xml version= "1.0" encoding= "Utf-8"?><manifest xmlns:android="Http://schemas.android.com/apk/res/android" package ="Com.example.baidu_demo1"android:versioncode="1"android: Versionname="1.0" > <uses-sdkandroid:minsdkversion="8"android:targetsdkversion ="/>" <!--Add Permissions -- <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.WAKE_LOCK"/> <uses-permission android:name="Android.permission.CHANGE_WIFI_STATE" /> <uses-permission android:name="Android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="Android.permission.GET_TASKS" /> <uses-permission android:name="Android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="Android.permission.WRITE_SETTINGS" /> <applicationandroid:allowbackup="true"android:icon="@drawable/ Ic_launcher "android:label=" @string/app_name "android:theme=" @style/ Apptheme " > <activityandroid:name="Com.example.baidu_demo1. Mainactivity "android:label=" @string/app_name " > <intent-filter> <action android:name="Android.intent.action.MAIN" /> <category android:name="Android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!--Add developer key -- <meta-dataandroid:name="Com.baidu.lbsapi.API_KEY"android:value= "Vf4kxbwl1mevoycfsml4yrlgpyz99xyf" /> </Application></manifest>
3, in Mainactivity, before using the SDK components to initialize the context information, passed into the ApplicationContext, note that the method to Setcontentview method before the implementation.
Create map activity to manage the map life cycle
PackageCom.example.baidu_demo1;ImportCom.baidu.mapapi.SDKInitializer;ImportCom.baidu.mapapi.map.MapView;Importandroid.app.Activity;ImportAndroid.os.Bundle; Public class mainactivity extends Activity {Mapview Mapview;@Override protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Sdkinitializer.initialize (Getapplicationcontext ()); Setcontentview (R.layout.activity_main); Mapview = (Mapview) This. Findviewbyid (R.id.bmapview); }@Override protected void OnDestroy() {//TODO auto-generated method stub Super. OnDestroy ();//Perform Mmapview.ondestroy () when activity executes OnDestroy to achieve map life cycle managementMapview.ondestroy (); }@Override protected void OnPause() {//TODO auto-generated method stub Super. OnPause ();//Perform mmapview when activity executes Onresume. Onresume () for map life cycle managementMapview.onpause (); }protected void Onresume() {Super. Onresume ();//Perform mmapview when activity executes Onresume. Onresume () for map life cycle managementMapview.onresume (); } }
[Android] Baidu Map development of the SDK development environment to build