1. Business Scenario: One of the methods in Baidu Map JavaScript API is to locate through browser, getCurrentPosition. But users refuse or allow access to geographical location, this.getStatus() is 0;
-
var myposition;
-
var myposition_lng;
-
var myposition_lat;
-
var geolocation = new BMap.Geolocation();
-
geolocation.getCurrentPosition(function(r){
-
if(this.getStatus() == BMAP_STATUS_SUCCESS){
-
var mk = new BMap.Marker(r.point);
-
map.addOverlay(mk);
-
map.panTo(r.point);
-
myposition_lat=r.point.lat;
-
myposition_lng=r.point.lng;
-
alert('accuracy:'+r.accuracy);
-
myposition=new BMap.Point(r.point.lng,r.point.lat);
-
}else {
-
alert('failed'+this.getStatus());
-
}
-
},{enableHighAccuracy: true})

2. Because when users refuse to use the browser's location, Baidu Map will get the approximate location by other means, so this.getStatus() is 0.
3. Solution: When the user refuses to use the browser location, the accuracy is null. By this value, the user can judge whether the user refuses to use the site to obtain the browser location information.

4. The code is as follows
-
var myposition;
-
var myposition_lng;
-
var myposition_lat;
-
var geolocation = new BMap.Geolocation();
-
geolocation.getCurrentPosition(function(r){
-
if(this.getStatus() == BMAP_STATUS_SUCCESS){
-
var mk = new BMap.Marker(r.point);
-
map.addOverlay(mk);
-
map.panTo(r.point);
-
myposition_lat=r.point.lat;
-
myposition_lng=r.point.lng;
-
-
myposition=new BMap.Point(r.point.lng,r.point.lat);
-
if(r.accuracy==null){
-
alert('accuracy null:'+r.accuracy);
-
-
return;
-
}
-
-
}else {
-
alert('failed'+this.getStatus());
-
}
-
},{enableHighAccuracy: true})