代码如下:
static OpenContinuosLocation() {
let request: geoLocationManager.ContinuousLocationRequest = {
'interval': 1,
'locationScenario': geoLocationManager.UserActivityScenario.NAVIGATION
}
let locationCallback = (location: geoLocationManager.Location): void => {
console.log('定位信息: ' + JSON.stringify(location));
};
try {
geoLocationManager.on('locationChange', request, locationCallback);
} catch (err) {
console.error("errCode:" + JSON.stringify(err));
}
}
1、可以通过设置LocatingPriority值提高精确度参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/location-guidelines-V5
2、排查一下是否是坐标系的问题,location返回的位置都是基于WGS84坐标系的,而国内使用的是GCJ02坐标系,建议在调用geoLocationManager.getCurrentLocation方法获取到的经纬度后,当发现有偏差时,使用坐标转换接口,把WGS84坐标转换为GCJ02坐标系再访问;坐标转换请参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/map-convertcoordinate-V5