Android Baidu Map SDK v3.0.0 (i)

Source: Internet
Author: User

Reprint please indicate source: http://blog.csdn.net/lmj623565791/article/details/37729091

Recently the company to Baidu Map integration project, so I studied the day Baidu Map SDK, the current version number: Android SDK v3.0.0.

Although Baidu Map online related code is much more. Most may be older version number, and Baidu Map API changes feel also larger. So let's share with you the success of the day's work.

Below is a brief description of the features in the blog:

1. Function Introduction

A, the first must be the import map, then the map mode of some switch, normal. Satellites, real-time traffic, whatever.

b, positioning function, positioning the current position.


C, add the overlay dynamically, click on the overlay, pop-up layer and other effects.



D, combined with the direction of the sensor, for the location of the map function to join the direction, I am extremely road crazy, not the cardinal points. So this feature is very important to me, the phone keeps spinning, and I know which way to go now. The map shown directly is useless to me.

(My 360-degree rotating phone, observing the changes):



Switching to another mode is also pretty cool:


E, to provide offline map download, can greatly save the user's traffic, but also to ensure that the use of the map without network conditions.

Basically this is the above function. First article. or start from scratch. First of all Baidu map into the app again.

2. Application key

A, the application key, to the Baidu API console page: Http://lbsyun.baidu.com/apiconsole/key


Enter the name you want to apply, choose the app type, and enter security.

b, about the security code (digital signature; package name) Acquisition:

Open the IDE:

The black box is the digital signature, then the package name is the package name we apply. Connect directly with semicolons: for example: f5:10:39:d9:81:57:bd:2e:a0:cd:e3:eb:5e:c4:cc:e0:e0:0d:41:56;com.zhy.zhy_baidu_ditu_demo03

Finally click Finish. To get the key:



3, the first Baidu map application

Download not much to say, directly click on the official website of the relevant download can choose, I will also post the source code.

Configuration:

The first step: Create a new Libs folder in Project, copy the Baidumapapi_vx_x_x.jar in the development package to the Libs root folder, and copy libbaidumapsdk_vx_x_x.so to Libs\ Under the Armeabi folder (the two files are already in the website demo, it is assumed to be integrated into your project.) You need to join yourself). The project folder after the copy is finished, for example, as seen;

Note: liblocsdk3.so and Locsdk_3.1.jar for Baidu to locate the use of the SDK resources, developers can be based on the actual needs of their own to join.


Android_dev1.png
Step two: Select "Add External JARs" in the project properties->java Build path->libraries, Baidumapapi_vx_x_x.jar selected, 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 features.


Note: Because the ADT plugin is upgraded. If you are using Eclipse ADT 22. The development environment needs to be set up in a corresponding setting. Methods such as the following:
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.


A. Join the development key in application

<application <meta-data android:name= "Com.baidu.lbsapi.API_KEY" android:value= "developer KEY"/> </ Application>


B. Join 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 "/> 


C. Add a map control to the layout file


<com.baidu.mapapi.map.mapviewandroid:id= "@+id/id_bmapview" android:layout_width= "Fill_parent" Android:layout_ height= "Fill_parent" android:clickable= "true"/>


D. Initialize the context global variables referenced by the SDK at the time of application creation:

@Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Requestwindowfeature (window.feature_no_title);//Initialize the context information before using each component of the SDK, passing in the applicationcontext// Note that this method is to be implemented before Setcontentview method Sdkinitializer.initialize (Getapplicationcontext ()); Setcontentview (r.layout.activity _main);}


Well, after these four steps you can show the map ~ ~

E, just the map is very power-hungry. So it's necessary to manage its declaration cycle

Package Com.zhy.zhy_baidu_ditu_demo00;import Android.app.activity;import Android.os.bundle;import Android.view.window;import Com.baidu.mapapi.sdkinitializer;import Com.baidu.mapapi.map.mapview;public Class Mainactivity extends activity{private mapview mmapview = null; @Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Requestwindowfeature (window.feature_no_title);// Before using the SDK components to initialize the context information, pass in applicationcontext//Note that the method is implemented before Setcontentview the method Sdkinitializer.initialize ( Getapplicationcontext ()); Setcontentview (r.layout.activity_main);//Get map Control Reference Mmapview = (Mapview) Findviewbyid ( R.id.id_bmapview);} @Overrideprotected void OnDestroy () {Super.ondestroy ();//Run Mmapview.ondestroy () while the activity is running OnDestroy. Implement map life cycle management Mmapview.ondestroy (); mmapview = null;} @Overrideprotected void Onresume () {super.onresume ();//Run Mmapview when activity runs Onresume. Onresume (), Implement Map Lifecycle Management Mmapview.onresume ();} @Overrideprotected void OnPause () {super.onpause ();//Run Mmapvie when activity runs OnPauseW. OnPause (), Implementing Map Lifecycle Management Mmapview.onpause ();}} 


All right, over. In fact, the Baidu Development Guide on the HelloWorld This article is also extremely clear ~ ~ ~



Source code click to download


Baidu Map Related Blog Video version number has been online: the use of Baidu map in Android look forward to your support.



Bo Master part of the video has been online, assuming you do not like boring text, please poke (first record, look forward to your support):

1. Android self-defined control scratch card in real-action e-commerce activities

2. Android Self-defining controls to build Android streaming layouts and popular tags

3. android Robot "Little Mu" implementation

4, high imitation QQ5.0 sideways slip

5, High imitation 5.2.1 main interface and message alert






Android Baidu Map SDK v3.0.0 (i)

Related Article

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.