移动设备的距离跟踪精度



我正在编写一个距离跟踪器,旨在用手机跟踪汽车行驶的里程。 我正在使用科尔多瓦和科尔多瓦地理位置插件。 代码似乎在地理位置插件接收坐标的地方正确运行,我使用haversine公式来计算两个坐标之间的距离。 但是,我的跟踪器不准确,因为我天真地使用了不准确的纬度/纬度坐标。 看来positionposition.accuracyposition.speed. 因此,我希望其中一个或两个属性可能有用。

精度

:纬度和经度坐标的精度级别(以米为单位(。(数字( 速度:设备的当前地面速度,以米/秒为单位指定。(数字(

我的问题是:是否有已知的跟踪距离解决方案可以处理手机上可能不准确的纬度/纬度信息?

更具体的问题:

  • 位置速度在手机上的准确度如何?
  • 有没有一个位置.准确性是手机倾向于的? (我很好奇,因为我正在考虑忽略带有位置精度>阈值的纬度/纬度线。 所以我试图弄清楚一个好的阈值是什么(

这是我当前代码的片段:

function DistanceTracker() {
    this._currentPosition = null;
    this.miles = 0.0;
}
DistanceTracker.prototype.start = function () {
    var self = this;
    navigator.geolocation.watchPosition(
        /*success*/function (position) {
            self.updateDistance(position);
        },
        /*fail*/function (errorPosition) { 
            //exception handling uses https://github.com/steaks/exceptions.js
            throw new exceptions.Exception("Error in geolocation watchPosition", { data: errorPosition }); 
        },
        { enableHighAccuracy: true, timeout: 5000 });
    )
};
DistanceTracker.prototype.updateDistance = function (position) {
    if (this._currentPosition !== null) {
        this.miles = this.miles + this.getDistanceFromLatLonInMiles(
            this._currentPosition.coords.latitude,
            this._currentPosition.coords.longitude,
            newPosition.coords.latitude,
            newPosition.coords.longitude);
    }
};
//Copied from http://stackoverflow.com/questions/27928/how-do-i-calculate-distance-between-two-latitude-longitude-points
function getDistanceFromLatLonInMiles(lat1,lon1,lat2,lon2) {
    var R = 6371; // Radius of the earth in km
    var dLat = deg2rad(lat2-lat1);  // deg2rad below
    var dLon = deg2rad(lon2-lon1);
    var a =
        Math.sin(dLat/2) * Math.sin(dLat/2) +
        Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
        Math.sin(dLon/2) * Math.sin(dLon/2)
        ;
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    var d = R * c; // Distance in km
    return d * KILOMETERS_TO_MILES_RATIO;
}
function deg2rad(deg) {
    return deg * (Math.PI/180);
}

我建议使用英尺或米而不是公里来表示哈弗辛。我发现它更准确。我知道这似乎不应该有什么不同。试试吧。

取代 var R = 6371;地球半径(公里(

跟 var R = 20890584;//英尺

最新更新