Baidu Map Android SDK-Hello Baidu Map
The following describes how to use Baidu map Android SDK to build a basic map application!
Step 1: Create an Android project and import the Android SDK of Baidu map to the corresponding Project location:
Create a libs folder in the project, copy the baidumapi_vx_x_x.jar in the development package to the libs root directory, and copy libBaiduMapSDK_vX_X_X.so to the libs \ armeabi directory (the two files are already in the demo on the official site, if you want to integrate it into your own project, you need to add it yourself.) The copied project directory is shown in;
Note: liblocSDK3.so and locSDK_3.1.jar are resources used by Baidu positioning SDK. developers can add them as needed.
Step 2: add the corresponding jar (add jar) to the created Android project ): <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + signature + CjwvcD4KPHA + zai5/dLUyc/Signature + signature/Signature/Co7o8YnI + CjwvcD4KPHA + signature + tdrI/Signature + qt6LD3NS/tcS78ciht73Kvcfrss6/far + u/qreiw9zUvzwvcD4KPHA + PC9wPgo8cHJlIGNsYXNzPQ = "brush: java; ">
Step 4: add the required permissions to the AndroidManifest file of the project:
The required permissions are as follows and added to the AndroidManifest file:
Step 5: Add a map control (MapView) to the XML layout file ):
Add the MapView control as follows:
Step 6: Initialize the SDK when creating an application:
Note: Before using SDK functional components, you must call SDKInitializer. initialize (getApplicationContext (). Therefore, we recommend that you put this method in the Application initialization method.
Public class MainActivity extends Activity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); // initialize the context information before using the SDK components, and pass in the ApplicationContext // note that this method must be implemented before the setContentView method. initialize (getApplicationContext (); setContentView (R. layout. activity_main );}}
Step 7: create a map activity file and manage its lifecycle:
Public class MainActivity extends Activity {MapView mMapView = null; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); // initialize the context information before using the SDK components, and pass in the ApplicationContext // note that this method must be implemented before the setContentView method. initialize (getApplicationContext (); setContentView (R. layout. activity_main); // obtain the map control reference mMapView = (MapView) findViewById (R. id. bmapView) ;}@ Override protected void onDestroy () {super. onDestroy (); // execute mMapView when onDestroy is executed in activity. onDestroy () to implement mMapView for map lifecycle management. onDestroy () ;}@ Override protected void onResume () {super. onResume (); // execute mMapView when onResume is executed in the activity. onResume () to implement mMapView for map lifecycle management. onResume () ;}@ Override protected void onPause () {super. onPause (); // execute mMapView when onPause is executed in activity. onPause () enables mMapView for map lifecycle management. onPause ();}}
Step 8: run the APP to display the basic map: