Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript地理位置:检查与2个gps坐标的距离_Javascript_Html_Geolocation_Gps - Fatal编程技术网

JavaScript地理位置:检查与2个gps坐标的距离

JavaScript地理位置:检查与2个gps坐标的距离,javascript,html,geolocation,gps,Javascript,Html,Geolocation,Gps,我有两个常数-拉利度和长度。我通过HTML5JSAPI获得用户位置getCurrentPosition()方法提供coords.accurity来显示位置的准确性。 我需要检查距离gps坐标的常数和getCurrentPosition()是否小于10米 是否有库或jQuery插件,或者我必须自己编写?下面的代码是我在Google Maps API v3中使用的代码。也许您可以对您的库执行类似的操作。哈弗森公式将地球视为一个球体,这是我计算距离的最佳选择。谷歌API附带了一个额外的功能来实现这一点

我有两个常数-拉利度和长度。我通过HTML5JSAPI获得用户位置
getCurrentPosition()
方法提供
coords.accurity
来显示位置的准确性。 我需要检查距离gps坐标的常数和
getCurrentPosition()
是否小于10米


是否有库或jQuery插件,或者我必须自己编写?

下面的代码是我在Google Maps API v3中使用的代码。也许您可以对您的库执行类似的操作。哈弗森公式将地球视为一个球体,这是我计算距离的最佳选择。谷歌API附带了一个额外的功能来实现这一点

通常情况下,您会找到自己的库来计算距离,并提出自己的逻辑。 同样,从这个逻辑中获取您所需要的,并尝试您找到的库

orderMarkersByDistance: function (markers) {
    var flex = this,
        geodesic = [],
        arrClosest = [],
        to, distance, arrDistances,
        map = this.root.gmap3("get");

    // loop through markers and calculate their distances from the center
    for (var i = 0; i < markers.length; i++) {
        to = new google.maps.LatLng(markers[i].lat, markers[i].lng);
        distance = google.maps.geometry.spherical.computeDistanceBetween(map.center, to);
        geodesic.push([i, distance]);
    }

    // sort the distances
    geodesic.sort(function (a, b) { return a[1] - b[1]; });

    // optionally, take the closest distances
    arrDistances = geodesic.slice(0, 3);

    // return closest markers
    $.each(arrDistances, function (idx, item) {
        arrClosest.push(markers[item[0]]);
    });

    return arrClosest;
},
orderMarkersByDistance:函数(标记){
var flex=这个,
测地线=[],
arr=[],
到,距离,距离,
map=this.root.gmap3(“get”);
//循环通过标记并计算它们与中心的距离
对于(var i=0;i
我找到了这些工作代码:还有什么更好?看起来不错,但你需要连接互联网。我想要离线(移动)应用程序。啊,就是这样,可能想把它添加到你的问题中,因为我不清楚。