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

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, map positioning function to join the direction. I am extremely road fetish. Regardless of the cardinal points, so this feature is very important to me, mobile phone constantly rotating, I know the current should go which way, direct display of the map is useless to me.

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



Switching to another mode is also pretty cool:


E, provide offline map download, can greatly save the user's traffic. can also guarantee the use of maps in the absence of network conditions.

Basic this above function, first article. Or from the beginning of zero, the first 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. Select 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

After the last click, you can get the key:



3, the first Baidu map application

The download will not say much. Directly click on the official website of the relevant download can be selected. I will also post the source code later.

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, if you want to integrate into your project, you need to add it yourself), after copying the project folder for example to see;

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 of the ADT plugin upgrade, if you are using Eclipse ADT 22. The development environment needs to be set up in such a way 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);//Initializes the context information before using each component of the SDK. Incoming 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 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 ();//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 (). Implement map life cycle management Mmapview.onpause ();}}


All right. Complete. 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, if you do not like the boring text, please poke (first record). Looking 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)

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.