7

我正在使用 Capacitor 构建我的 Ionic 应用程序。我当然想通过 GPS 在地图上显示当前位置的应用程序。

以下代码有效,并为我提供了我想要的地图上的正确标记,但是.. 它远非准确。

async getLocation() {
    var self = this;
    let location = await Geolocation.getCurrentPosition({
        enableHighAccuracy: true,
        timeout: 1000
    });
    self.marker.setLngLat([location.coords.longitude, location.coords.latitude])
    const wait = Geolocation.watchPosition({enableHighAccuracy: true, timeout: 1000}, (position, err) => {
        self.marker.setLngLat([position.coords.longitude, position.coords.latitude])
    });
}

标记正在疯狂地四处走动。发生在我测试它的每个位置。它不是在移动几厘米,而是在我的位置周围移动几米……

我错过了什么让我的 GPS 坐标不太准确?我以为enableHighAccuracy: true足够了,但事实并非如此。

4

1 回答 1

3

位置信息可以从不同的位置提供者返回:卫星、网络、无源。为了获得最佳结果,您应该放弃网络和被动提供商提供的位置。

据我所知,现代位置 API 不区分提供者(参见融合位置),但您始终可以检查coords.accuracy以了解位置的准确性。

如果通过卫星对位置进行三角测量,那么准确度总是最好的。通常低于 16(以米为单位),但绝对低于 30。您可以安全地丢弃精度高于此的坐标。

于 2019-06-10T14:20:35.640 回答