1. Create an app to get AK (I understand application key)
Through Baidu account login Baidu map Open platform, enter the API console Http://lbsyun.baidu.com/apiconsole/key to create their own applications, enter the application name, select the Android SDK app type, select the desired service (default selection) Enter the signature file SHA1, the default signature file Debug.keystore under C:\Users\ your user \.android, and then open the console CD to this directory by typing keytool-v-list-keytore Debug.keystore, you can get the signature file SHA1 Note that the copy should not have a space, and then enter the package name of the application, do not enter the wrong, the system generates security code itself, the submission is created.
2. Download the SDK and integrate it into your project
Select the type of service you want, then download the SDK to download the demo,http://lbsyun.baidu.com/index.php?title=androidsdk/sdkandev-download, unzip it after the download is complete, Put the jar and so files below the Lib under the Libs of the project, compile Filetree (include: [' *.jar '], dir: ' Libs ') Build.grade This statement only needs to be added under Android Sourceset{main {jnilib.dir (' libs ')}} This place Baidu development documentation is a bit vague, you can also create your own JniLib folder to add so files, but do not do at the same time.
Then add the permissions service (location required) in the manifest file mata (just change your AK), and be careful not to put it in the wrong place. Baidu development documents are not pasted http://lbsyun.baidu.com/index.php?title=androidsdk/guide/hellobaidumap.
3. Display map location Add overlay geocoding, etc.
Introduce Mapview in your own XML file, initializing the map's SDK sdkinitializer.initialize (Getapplicationcontext ()) in Java code; Get Mapview and implement the Mapview cycle in the activity life cycle, to the current position, run the application can see the effect of the map, Beijing.
Through the locationclient, Baidumap, Bdlocationlistener to achieve the positioning function through the Mapview get baidumap settings locationclient parameters and listeners, Implement the Bdlocationlistener interface, and then turn on the location Locationclient.start () to obtain information such as location via the interface callback.
Change the location of the map and add your own location by latitude and longitude
A, the location of the mobile map
LATLNG ll = new Latlng (Location.getlatitude (),
Location.getlongitude ());
Mapstatusupdate update = MAPSTATUSUPDATEFACTORY.NEWLATLNG (ll);
Move to a latitude
Mbaidumap.animatemapstatus (update);
B. Add your own location
Mbaidumap.setmylocationenabled (TRUE);
Constructing positioning data
Mylocationdata locdata = new Mylocationdata.builder ()
. Accuracy (Location.getradius ())
Here you set the direction information the developer gets, clockwise 0-360
. direction (+). Latitude (Location.getlatitude ())
. Longitude (Location.getlongitude ()). build ();
Setting location data
Mbaidumap.setmylocationdata (Locdata);
C, through mbaidumap.addoverlay (option); Add cover marker and other reference Baidu documentation
Add marker
Building the marker icon
Bitmapdescriptor bitmap = bitmapdescriptorfactory
. Fromresource (drawable);
Build markeroption to add marker on the map
overlayoptions option = new Markeroptions ()
. Position (Point)
. icon (bitmap);
Add marker on the map and show
Mbaidumap.addoverlay (option);
D, add line, etc., PTS is a set list<latlng>
Overlayoptions polylineoption = new Polylineoptions ()
. Points (pts). Width (5). Color (0xffff0000)
;
Mbaidumap.addoverlay (polylineoption);
E, GeoCode Enter a location to return latitude and longitude
Msearch = Geocoder.newinstance (); Gets the instance object set listener, implements the listener interface Ongetgeocoderresultlistener, the callback result can obtain the information, the attention is all asynchronous, There are, of course, anti-geocoding.
Baidu map to achieve a lot of functions, you can think of what you need to provide.
Android Open Baidu Map integration