Open Baidu map integration for Android and open map for android

Source: Internet
Author: User

Open Baidu map integration for Android and open map for android

1. Create an Application to obtain the AK (I understand it as the Application key)

Through the Baidu Account Login Baidu map open platform, enter the API console http://lbsyun.baidu.com/apiconsole/key to create their own application, enter the application name, select the Android SDK application type, select the desired service (all by default) enter the SHA1 of the signature file. The default signature file is debug. keystore in C: \ Users \ your user \. in android, open the console cd and enter keytool-v-list-keytore debug in this directory. keystore, you can get the SHA1 of the signature file. Note that there should be no space during copying, enter the package name of the application, or enter an error. The system generates a security code by itself, the creation is complete after submission.

2. Download the SDK and integrate it into your own project.

Select the desired service type, and then download the SDK can also download demo, http://lbsyun.baidu.com/index.php? Title = androidsdk/sdkandev-download. decompress the downloaded package and put the jar and so files under lib into the libs of the project. compile fileTree (include :['*. jar '], dir: 'libs') build. with this statement in grade, you only need to add sourceSet {main {jniLib. dir ('libs')}. This is a bit fuzzy in Baidu development documentation. You can also create a jniLib folder to add so files, but do not do it all at the same time.

Then add the permission service (positioning required) mata to the list file (you only need to change your ak). Do not put the wrong location. Baidu development documentation are not pasted http://lbsyun.baidu.com/index.php? Title = androidsdk/guide/hellobaidumap.

3. Display map positioning, add overlay geographic codes, etc.

Introduce mapview into your xml file and initialize the map SDK SDKInitializer in Java code. initialize (getApplicationContext (); obtain the mapview and implement the mapview cycle in the activity lifecycle. At the current position, run the application to see the map effect, Beijing.

You can use the LocationClient, BaiduMap, and BDLocationListener functions to obtain parameters and listeners for setting LocationClient through the baidumap through mapview, implement the BDLocationListener interface, and enable location LocationClient. start (). You can obtain location information by calling back the location through the interface.

Use latitude and longitude to change the positions displayed on the map and add the positions of the map.

A. Position of the mobile Map
LatLng ll = new LatLng (location. getLatitude (),
Location. getlongpolling ());
MapStatusUpdate update = MapStatusUpdateFactory. newLatLng (ll );
// Move to a longitude and latitude
MBaiduMap. animateMapStatus (update );

B. add your own location
MBaiduMap. setMyLocationEnabled (true );
// Construct the positioning data
MyLocationData locData = new MyLocationData. Builder ()
. Accuracy (location. getRadius ())
// Set the direction information obtained by the developer, Which is 0-360 clockwise.
. Direction (100). latitude (location. getLatitude ())
. Longpolling (location. getlongpolling (). build ();
// Set the positioning data
MBaiduMap. setMyLocationData (locData );

C. Use mBaiduMap. addOverlay (option) to add a covering marker. Refer to Baidu documentation.
// Add a marker
// Construct the Marker icon

BitmapDescriptor bitmap = BitmapDescriptorFactory
. FromResource (drawable );
// Construct a MarkerOption to add a Marker to a map
OverlayOptions option = new MarkerOptions ()
. Position (point)
. Icon (bitmap );
// Add a Marker to the map and display it
MBaiduMap. addOverlay (option );

D. Add a line. pts is a collection List <LatLng>
OverlayOptions polylineOption = new PolylineOptions ()
. Points (pts). width (5). color (0XFFff0000)
;
MBaiduMap. addOverlay (polylineOption );

E. Input a location in geocode to return the longitude and latitude.
MSearch = GeoCoder. newInstance (); gets the listener set for the Instance Object and implements the listener interface OnGetGeoCoderResultListener. The callback result can be used to obtain the information. Note that the information is asynchronous and there is also anti-Geographic Encoding.

Baidu map provides many functions that you can think.



 

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.