【发布时间】:2019-10-31 07:19:36
【问题描述】:
我有一个使用 cordova 和 google maps api 的 ionic 4 应用程序。我正在使用 HTML5 geoloction 插件,它会在用户移动时观察设备的位置,然后生成一个新的 googleMaps 标记并将其显示在地图上。
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
});
使用上面的代码,我已经在三星 note 9 上测试了该应用程序,结果是 100% 准确的。我还在其他安卓设备(Galaxy A20 和华为 Y5)上测试了相同的应用程序,结果并不准确,而是标记从我的位置跳出大约 50 到 200 米。
【问题讨论】:
-
您是否尝试设置 enableHighAccuracy 选项?见stackoverflow.com/questions/43288402/…
-
很高兴听到,不客气!然后将此作为完整答案发布。 :)
标签: javascript google-maps cordova geolocation ionic4