[英]Given a random lat/lon, find nearest co-ordinate(lat/lon) from given the list of co-ordinates implying the direction of traveling
Need to write below function to calculate distance given 3 inputs: 给定3个输入,需要编写以下函数来计算距离:
Need to find the distance between 2 and 3, keeping the direction of the loop in mind. 需要找到2到3之间的距离,并牢记循环的方向。
PS, More like how Google is finding distance given two points given a route. PS,更像是Google如何根据给定路线的两个点来查找距离。 But cant use Google APIs.
但不能使用Google API。
Here you can find formulas and JS code to get distance between coordinates 在这里您可以找到公式和JS代码以获取坐标之间的距离
JavaScript:
var R = 6371e3; // metres
var φ1 = lat1.toRadians();
var φ2 = lat2.toRadians();
var Δφ = (lat2-lat1).toRadians();
var Δλ = (lon2-lon1).toRadians();
var a = Math.sin(Δφ/2) * Math.sin(Δφ/2) +
Math.cos(φ1) * Math.cos(φ2) *
Math.sin(Δλ/2) * Math.sin(Δλ/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
As far as I understand, you have to check distances between point and all stop nodes in order. 据我了解,您必须按顺序检查点与所有停止节点之间的距离。
The smallest sum of distances of PS[i]
and PS[i+1]
reveals the most close segment to that point (does not work always - for example, for self-intersecting paths etc) PS[i]
和PS[i+1]
的最小距离总和显示了与该点最接近的线段(并非总是起作用-例如,对于自相交路径等)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.