Android's Baidu Map Development (ii) positioning

Source: Internet
Author: User

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 {
    • 1
@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(); //开启定位
    • 1
//关闭定位
 

Android's Baidu Map Development (ii) positioning

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.