Android using Baidu lbs SDK (a) show map Mapview

Source: Internet
Author: User

Similar to Baidu application engine, the use of Baidu's lbs service, first of all, we create an application in the Baidu Open service platform, such as:


Go to App details and click on "lbs Service" to set up your app:



The way digital signatures are obtained can be viewed in eclipse (ADT 22), WINDOW->PREFERENCES->ANDROID->BUILD,SHA1 fingerprint is what we need:


Android SDK Security Code composition: Digital Signature +;+ package name.


Then download the lbs Android SDK, then follow the official Baidu document method to operate:

The first step: Create a new Libs folder in the project, copy the Baidumapapi_vx_x_x.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: liblocsdk3.so and Locsdk_3.1.jar are the resources used by Baidu to locate the SDK, and developers can add their own according to their 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.


Then configure the relevant permissions and keys in our app:

(1) Add the 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-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) Initializes the context global variables referenced by the SDK when the application is created:

public class Mainactivity extends Activity {      @Override      protected void onCreate (Bundle savedinstancestate) {          super.oncreate (savedinstancestate);           Initialize the context information before using each component of the SDK, passing in ApplicationContext          //Note that the method is implemented          before setcontentview the method Sdkinitializer.initialize (Getapplicationcontext ());          Setcontentview (R.layout.activity_main);      }  }



(5) Managing the map life cycle:

public class Mainactivity extends Activity {Mapview mmapview = null;           @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Initialize the context information before using each component of the SDK, passing in ApplicationContext//Note that the method is implemented before Setcontentview the method sdkinitializer.initialize          (Getapplicationcontext ());          Setcontentview (R.layout.activity_main);      Gets the map control reference Mmapview = (Mapview) Findviewbyid (R.id.bmapview);          } @Override protected void OnDestroy () {Super.ondestroy ();      Execute Mmapview.ondestroy () when activity executes OnDestroy, implement map life cycle management Mmapview.ondestroy ();          } @Override protected void Onresume () {super.onresume (); Executes Mmapview when the activity executes Onresume.          Onresume () To achieve Map Lifecycle management mmapview.onresume ();          } @Override protected void OnPause () {super.onpause (); Executes Mmapview when the activity executes OnPause. OnPause () for map life cycle management MMAPVIEw.onpause (); }      }

Here you can show the map, but only show Beijing, and no positioning, tomorrow to summarize the implementation of the positioning.



Reprint Please specify source: Zhou Mushi's csdn blog Http://blog.csdn.net/zhoumushui

My github: Zhou Mushi's GitHub Https://github.com/zhoumushui




Android using Baidu lbs SDK (a) show map Mapview

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.