Android uses Baidu lbs sdk (I) to display map MapView and androidmapview

Source: Internet
Author: User

Android uses Baidu lbs sdk (I) to display map MapView and androidmapview

Similar to the Baidu application engine, Baidu's LBS service is used. First, we create an application on the Baidu open service platform, for example:


Go to application details, click "LBS service", and set the application:



You can view the digital signature Acquisition Method in Eclipse (ADT 22). Window> Preferences> Android> Build and SHA1 fingerprint are what we need:


Android SDK security code: Digital Signature +; + package name.


Download the LBS Android SDK and follow the instructions in the official Baidu documentation:

Step 1: Create a libs folder in the project, copy the baidumapapi_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 available in, 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: Select Add External JARs in Project Properties> Java Build Path> Libraries, select baidumapapi_vX_X_X.jar, and return.

After the preceding two steps, you can use all the functions provided by Baidu map SDK.

Note: Due to the adt plug-in upgrade, if you use Eclipse adt 22, you need to set the development environment as follows:

1. Select a project in Eclipse, right-click the project and choose Properties> Java Build Path> Order and Export to make Android Private Libraries in the check box;

2. Project-> clean all.


Then configure related permissions and keys in our application:

(1) Add a development Key to the application:

<Application> <meta-data android: name = "com. baidu. lbsapi. API_KEY" android: value = "Developer key"/> </application>

(2) Add required permissions

<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" />
(3) Layout
<com.baidu.mapapi.map.MapView      android:id="@+id/bmapView"      android:layout_width="fill_parent"      android:layout_height="fill_parent"      android:clickable="true" />

(4) initialize the Context global variable referenced by the SDK when creating an application:

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 );}}



(5) Manage map 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 ();}}

The map can be displayed here, but it can only be displayed in Beijing, and there is no positioning. I will summarize the implementation of positioning tomorrow.



Reprinted please indicate the source: Zhou mu Shui CSDN blog http://blog.csdn.net/zhoumushui

My GitHub: Zhou mu Shui's GitHub https://github.com/zhoumushui




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.