原因:navigator.geolocation.getCurrentPosition取到的经纬度属于WGS84坐标,并不能直接用在百度地图的 构建map的point中,需要通过convertor.translate([pointBak], 1, 5,function(resPoint) 转换。
navigator.geolocation.getCurrentPosition((position) => {
let lat = position.coords.latitude;
let lng = position.coords.longitude;
const pointBak = new BMap.Point(lng, lat);
const convertor = new BMap.Convertor();
convertor.translate([pointBak], 1, 5, function (resPoint) {
if (resPoint && resPoint.points && resPoint.points.length > 0) {
lng = resPoint.points[0].lng;
lat = resPoint.points[0].lat;
}
const point = new BMap.Point(lng, lat);
const geo = new BMap.Geocoder();
geo.getLocation(point, (res) => {
console.log(res);
});
});
});