我有一个使用 cordova 和 google maps api 的 ionic 4 应用程序。我正在使用 HTML5 geoloction 插件,它会在用户移动时监视设备的位置,然后生成一个新的 googleMaps 标记并将其显示在 map 上。
this.watchLocation = await this.geolocation
.watchPosition()
.subscribe(location => {
this.map.animateCamera({
target: {
lat: location.coords.latitude,
lng: location.coords.longitude
},
zoom: 16,
duration: 1000
});
this.marker.setPosition({
lat: location.coords.latitude,
lng: location.coords.longitude
});
使用上面的代码,我已经在 Samsung note 9 上测试了该应用程序,结果 100% 准确。我还在其他 Android 设备(Galaxy A20 和华为 Y5)上测试了相同的应用程序,但结果并不准确,而是标记从我的位置跳出大约 50 到 200 米的位置。
最佳答案
尝试将 enableHighAccuracy
选项设置为 true
。 docs描述如下:
The
PositionOptions.enableHighAccuracy
property is a Boolean that indicates the application would like to receive the best possible results. If true and if the device is able to provide a more accurate position, it will do so. Note that this can result in slower response times or increased power consumption (with a GPS chip on a mobile device for example). On the other hand, if false (the default value), the device can take the liberty to save resources by responding more quickly and/or using less power.
关于javascript - Cordova 地理定位不准确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58638500/