Setting location Mode

Device_Sensors is used when setting the positioning mode

LocationClientOption option = new LocationClientOption() option.setLocationMode(LocationClientOption.LocationMode.Device_Sensors); option.setScanSpan(0); // set 0: single position moption. setCoorType("bd09ll");Copy the code

The problem

The positioning interval is set to 0, indicating only one callback, but the printed result returns data twice:

D/DebugLog: ⇢ startLocation()
D/DebugLog: ⇠ startLocation [28ms]
D/DebugLog: ⇢ onReceiveLocation(bdLocation=&loctype=161&lat=32.001415&lon=118.749307&radius=43.813316&biasprob=-1.0)
D/DebugLog: ⇠ onReceiveLocation [0ms]
D/DebugLog: ⇢ onReceiveLocation(bdLocation=&loctype=61&lat=32.001381&lon=118.74885&radius=15.0&biasprob=-1.0)
D/DebugLog: ⇠ onReceiveLocation [12ms]
Copy the code

Tried in BDAbstractLocationListener callback execution stop positioning, and cancellation of listening

locationClient.stop(); locationClient.unRegisterLocationListener(listener); `Copy the code

After compiling again and starting, it still finds callback twice.

After checking the printed data, it was found that the two results were somewhat different, with different positioning modes, loctype=161 and loctype=61 respectively

Respectively corresponding to the location type of BDLocation. TypeNetWorkLocation and BDLocation TypeGpsLocation,

The positioning accuracy is also different, which can be seen in the printed results.

The solution

Can be a choice, the result of the two positioning requires rapid positioning can choose BDLocation. TypeNetWorkLocation, to high precision can choose BDLocation. TypeGpsLocation

 DialogHelper.doBeforeAsk(getAttachActivity(), "One-click alarm"."Are you sure you want to send an alarm?", dialog -> {
            showDialog("Obtaining location, please wait...");
            startLocation(new BDAbstractLocationListener() {
                @DebugLog
                @Override
                public void onReceiveLocation(BDLocation bdLocation) {
                    if(bdLocation.getLocType() ! = BDLocation.TypeGpsLocation) {// Make sure you only get the location once
                        return;
                    }
                    double latitude = bdLocation.getLatitude();
                    double longitude = bdLocation.getLongitude();
                    String jwd = longitude + ","+ latitude; ` ` ` ` ` `Copy the code

Another question

Using the fence function in Baidu positioning, it is found that the point position obtained by the fence interface is always offset from the data transmitted to Baidu positioning. I wonder if anyone knows how to solve this problem.