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 integrate Baidu Map project, so I studied the day Baidu Map SDK, the current version: Android SDK v3.0.0. Although Baidu Map online related code more, most likely are older version, and Baidu Map API changes feel is also relatively large, so again this share with you a day of labor success.

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, ordinary, satellite, real-time traffic and so on.

b, positioning function, positioning the current position.


C, dynamically add overlays, click on overlays, pop-up layers and other effects.



D, combined with the direction of the sensor, for the location of the map to add direction, I am extremely road crazy, regardless of the cardinal points, so this function for me is very important, mobile phone constantly rotating, I can know which road should be to go, direct display of the map is useless to me.

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



Switching to another mode is also awesome:


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.

Basic This function, the first article, or from scratch, first Baidu map into the app.

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 of our application, directly connected 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, you can get the key:



3, the first Baidu map application

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

Configuration:

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.
Android_dev1.png
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 the project in Eclipse, right-click Properties->java Build path->order and Export to make Android Private libraries tick;
2). Project, clean-> clean all.


A. Add the development key in application

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


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


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, but the map is very power-hungry, so it is 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 ();//Mmapview.ondestroy () is executed when activity executes OnDestroy, Implement map life cycle management Mmapview.ondestroy (); mmapview = null;} @Overrideprotected void Onresume () {super.onresume ();//Mmapview is executed when activity executes Onresume. Onresume (), Implement Map Lifecycle Management Mmapview.onresume ();} @Overrideprotected void OnPause () {super.onpause ();//execute Mmapvie when activity executes OnPauseW. OnPause (), Implementing Map Lifecycle Management Mmapview.onpause ();}} 


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



SOURCE Click to download



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.