How to use the Baidu Map SDK under Android

Source: Internet
Author: User
Tags map class root directory
The Android SDK is a set of application interfaces based on the Android 2.1 (v1.3.5 and previous versions that support Android more than 1.5 systems) and above-version devices

You can use this SDK to develop map applications for Android mobile devices, and by invoking the Map SDK interface, you can easily access the Baidu Map service and data to build a rich, interactive lbs (Map Class) application.

Baidu Map all the services provided by the Android SDK are free of charge, and the interface is used without limit. You will need to apply for key (key) before you can use the Google Maps Android SDK. Any non-profit products please use directly. The implication is that the profit of the product must help Baidu to give money.

First, Baidu Map API platform.

Baidu Map API URL: http://developer.baidu.com/map/sdk-android.htm

Baidu Map Development Steps are

① Get key
② to apply for a new key and view the original application key
③ Development Guide for using the Baidu map on Androping platform
The class and method descriptions provided by the ④ reference Map library are relevant downloads
Examples of related packages and descriptions used in ⑤ development

哝, this is the Baidu map of the APK platform interface:

First, we'll apply for key.

The steps are also very simple:

① Click to get the key ② enter the key application page and read the relevant terms of use ③ check read and agree to the terms ④ fill in the application name fill out the corresponding functions and description of the application ⑤ input verification code after the ⑥ key can apply for success

The key I am applying for is shown in the following figure:

How to import the jar package that you have requested into the project.

First, the new Libs folder in the project (if it does not exist), the development package in the Baidumapapi_v2_1_1.jar copy to the Libs root directory, will be libapp_baidumapapplib_v2_1_1. So and libvi_voslib.so are copied to the Libsarmeabi directory.

Second, the project properties in Java build Path->order and export, to determine the Android Private libaries and Android dependencies before the selection box is selected,

Third, Click to determine the menu Project->clean the project will be able to use the functions of the map to program.

Four, the Liblocksdk3.1.jar in the package and the corresponding so file is used for positioning and search functions, if you do not need to add to the project

The schema of the jar package is shown in the following illustration:

The appearance of the jar package is also shown in the following illustration:

Under the manifest file, the permissions to add.

<supports-screens android:anydensity= "true" android:largescreens= "true" android:normalscreens= "true" Android: Resizeable= "true" android:smallscreens= "true"/>

property settings for an activity that needs to load a map

<activity android:name= "com.dfrz.map.DFRZMapActivity" android:configchanges= "orientation|keyboardhidden| ScreenSize "android:label=" @string/app_name "android:screenorientation=" sensor "> </activity>

After these preparations are done, we need to get into the corresponding map control

<com.baidu.mapapi.map.mapview android:id= "@+id/bmapsview" android:layout_width= "Match_parent" Android:layout_ height= "Wrap_content" android:layout_weight= "1" android:clickable= "true"/>

The above XML source code is this is to load Baidu Map control box, this layout you can according to your own needs to adjust, or place to your activity need place. This control needs to receive a click event, so you need to set clickable to true.

The principle of Baidu's map is this .....

Maps, positioning, search functions need to be managed with the Bmapmanager object, Bmapmanager provides four interfaces: Init (), Start (), Stop (), destroy (). Generate the Bmapmanager object and initialize it in the application, call Destroy () when the program exits, call the start () method in the OnCreate () method of the activity that needs to use the SDK feature, and call the stop in the OnDestroy () method ( method, or Onresume ()/onpause () to call Start () and stop (), respectively. Common method: Destroy (): Invoke Boolean init (java.lang.String strkey, Mkgenerallistener Listener) to initialize the map engine before exiting the program, need to feed the Baidu map key bool Ean start (): Open Baidu Map API Boolean stop (): Stop Baidu Map API, call this function, no callback will occur.

mapview--Baidu Map of the display.

A view control that displays a map that captures key events and touch gestures to translate and scale the map Setbuiltinzoomcontrols (Boolean on) when the focus is selected: Set whether the built-in zoom control is enabled Getcontroller () : Returns the Mapcontroller of the map, which can be used to control and drive panning and scaling setdoubleclickzooming (Boolean bdoubleclickzooming): setting Mapview whether to support double-click magnification Getoverlays (): Gets the existing layer in the Map Control refresh (): Refreshes the map control.

How to use the Baidu map to achieve the positioning, which requires locationclient

The Core class Registerlocationlistener (Bdlocationlistener) of the location processing function receives the onreceivelocation (bdlocation) in the specified listener after the location data is received method to receive the relevant data and do the related processing constructs: The new Locationclient (Getapplicationcontext ()) setlocoption (locationclientoption) sets the positional parameter start ( To start the positioning function, this function is continuous, you can define interval refresh time stop () to end the positioning function, but the positioning parameters set up earlier will not disappear, you can start requestlocation () to initiate an asynchronous location request, if the location does not change, do not initiate a network request, Return directly to the last position. (2 intervals required greater than 1 seconds)

Locationclientoption the class that is used to locate the operation.

Setting the positioning of the location function Disablecache (Boolean) really indicates that disabling cache positioning Setopengps (Boolean) uses GPS, provided that the mobile phone has GPS positioning Setaddrtype (String) when the string is "all Returns this location address information, others do not return the format of Setcoortype (String) set return coordinates gcj02-state survey Bureau bd09 Baidu Mercator bd0911 Baidu Jingwei coordinate (mobile default) setscanspan (int) timing interval (ms) When this value is greater than 1000, the time at which this value is specified is initiated once, when this value is less than 1000 or when this value is not set, the Requestlocation () method is invoked once

This is the class that we need to define mainactivity. The corresponding source code is shown in the figure:

protected void OnDestroy () {Mapview.destroy (); if (Mapmanager!= null) {Mapmanager.destroy (); mapmanager = null;} super . OnDestroy (); }

With these preparations, the effect of the corresponding operation is as follows:

This is the Android under the Baidu map application of the approximate steps.

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.