【问题标题】:Cordova Geolocation Wrong Coordinates科尔多瓦地理定位错误的坐标
【发布时间】:2017-03-18 20:30:41
【问题描述】:

我正在编写一个应用程序来跟踪当前位置并使用 google.maps.Polyline 绘制它。 问题是即使停止,当前位置也会发生变化。直走时也会发生这种情况。像这样:

这是代码:

var watchOptions = { timeout: 1000, enableHighAccuracy: false // get the same behaviour with 'true' };

var track = []; // coordinates to draw with Polyline

watch = $cordovaGeolocation.watchPosition(watchOptions);

changeMarker(myMarker, latLng);

watch.then(
  null,
  function(err) {
    console.log(err);
  },
  function(position) {
    var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

    // push current position to array
    track.push({ lat: position.coords.latitude, lng: position.coords.longitude});

var trackPath = new google.maps.Polyline({
      path: track,  // pass coordinates
      strokeColor: "#2980b9",
      geodesic: true,
      strokeOpacity: 1.0,
      strokeWeight: 2
    });

    // draw on map
    trackPath.setMap($scope.map);

【问题讨论】:

    标签: cordova google-maps ionic-framework geolocation


    【解决方案1】:

    首先,设置enableHighAccuracy: false 将使用低精度网络三角测量,而enableHighAccuracy: true 将使用 GPS 硬件。对于导航(例如步行),您应该始终将其设置为 true。

    即使这样,GPS 位置也不准确,也会出现一些错误 - 多少取决于许多因素,例如设备中的 GPS 硬件、天空的任何遮挡(例如树木、建筑物)以及有多少卫星被锁住了。

    为了能够频繁发送高精度位置,我建议设置如下:

    {
      enableHighAccuracy: true,
      maxAge: 0,
      timeout: 30000
    }
    

    【讨论】:

    • 使用 wi-fi 时,位置比使用蜂窝数据更准确。有没有办法防止坐标错误?
    • 应该有一个position.coords.accuracy 值,表示以米为单位的近似精度。对于蜂窝数据,此值会更高,因此您可以使用它来忽略过于不准确的位置,即if(position.coords.accuracy > 50) return console.log("Ignoring position as it's too inaccurate")
    • 嘿@DaveAlden 您在评论行中回答了兄弟,我使用的是相同的配置,但这不是问题,因为我看到了您的评论并为该准确性设定了门槛,我的问题解决了。谢谢。
    猜你喜欢
    • 2018-07-20
    • 1970-01-01
    • 2015-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-21
    相关资源
    最近更新 更多