javascript - Cordova 地理定位不准确

标签 javascript google-maps cordova geolocation ionic4

我有一个使用 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 米的位置。

Galaxy Note 9 结果: enter image description here

最佳答案

尝试将 enableHighAccuracy 选项设置为 truedocs描述如下:

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.

另请参阅相关主题 Very High Accuracy in Html5 Geolocation

关于javascript - Cordova 地理定位不准确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58638500/

相关文章:

google-maps - flutter 中更新Google Maps AlertDialog中的标记

javascript - 使用 Javascript 和 Angularjs 循环

android - Phonegap - Android 地理定位不准确

angularjs - ReferenceError:在Ionic App中未定义媒体

javascript - 如何从 mac 中完全删除 Ionic 和 Cordova 安装?

javascript - 对方法或属性访问的意外调用。微软客户关系管理

javascript - 在 d3.js 图表上显示 6 月而不是 1 月的年度 X 标签

javascript - onclick执行php函数而不重新加载页面

Javascript - 按每个数组中元素的升序重新排列数组元素

javascript - 谷歌地图请求返回 "Cannot set property ' position' of undefined"