Reference: http://blog.csdn.net/mr_wzc/article/details/51590485
The first step is to initialize the Locationclient class
Gets the map control reference Mmapview = (Mapview) Findviewbyid (R.id.bmapview); Mlocationclient =New Locationclient (Getapplicationcontext ());Declares the Locationclient class Mlocationclient.registerlocationlistener (this);Register the Listener function initlocation ();Turn on the positioning layer Mbaidumap = Mmapview.getmap (); Mbaidumap.setmylocationenabled (true);Display the positioning layer and can trigger the positioning, the default is Flase Mlocationclient.start ();Turn on positioning
Second Step, configure the Location SDK parameters
private void Initlocation () {locationclientoptionoption = new Locationclientoption ();Option.setlocationmode (LocationClientOption.LocationMode.Hight_Accuracy);//selectable, default high precision, set positioning mode, high accuracy, low power, device onlyOption.setcoortype ("Bd09ll");//optional, default GCJ02, set return positioning result coordinate system int span =1000;Option.setscanspan (span);//optional, default0, that is, only once, set the interval for initiating the location request to be greater than or equal to1000MS is effective.Option.setisneedaddress (true);//optional, set whether address information is required, default does not needOption.setopengps (true);//optional, defaultFalse to set whether to use GPSOption.setlocationnotify (true);//optional, defaultFalse to set whether the GPS is in effect when1S1 Secondary frequency output GPS resultsOption.setisneedlocationdescribe (true);//optional, default false, set whether to require positional semantics results, can be obtained in bdlocation.getlocationdescribe, the result is similar to "near the gate of the Beijing Tian ' an" Option.setisneedlocationpoilist (true);//optional, default false, set whether POI results are required, can be obtained in bdlocation.getpoilist Option.setignorekillprocess (false);//optional, default True, the location SDK inside is a service, and put in a separate process, set whether to kill the process at stop, the default does not kill Option. Setignorecacheexception (false);//optional, default false, sets whether to collect crash information, default collection Option.setenablesimulategps ( FALSE);//optional, default false, set whether you need to filter GPS simulation results, default requires mlocationclient.setlocoption (option);}
The third step is to implement the Bdlocationlistener interface and implement the incomplete method
public class MainActivity extends Activity implements BDLocationListener {
@Override public void Onreceivelocation (bdlocation location) {Mylocationdata Locdata = new Mylocationdata. Builder (). Accuracy (Location. Getradius ())//here to set the direction information the developer obtains, clockwise0-360. Direction (100). Latitude (Location. Getlatitude ()). Longitude (Location. Getlongitude ()). Build ().setmylocationdata (locData) .getlatitude (), Location.getlongitude ()) .newlatlngzoom (LL, 16" ;//set the map center and zoom level Mbaidumap.maketext (Getapplicationcontext (), location .getaddrstr (), Toast.show () ;}
Fourth step, start positioning and closing the positioning
mLocationClient.start(); //开启定位
//关闭定位
Android's Baidu Map Development (ii) positioning