简体   繁体   English

给定随机纬度/经度,从给定隐含行进方向的坐标列表中找到最接近的坐标(纬度/经度)

[英]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个输入,需要编写以下函数来计算距离:

  1. List of stops with coordinates, which also implies the direction of travelling. 带有坐标的停靠点列表,这也意味着行进方向。 More like a polygon or which would form the closed loop. 更像一个多边形或将形成闭环。
  2. Random co-ordinate around the loop. 围绕循环的随机坐标。
  3. One of the co-ordinate from the list given in point 1. 点1中给出的列表中的坐标之一。

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.

相关问题 如何从坐标列表中计算到给定点的最近坐标 - How to calculate the closest co-ordinates to a given point from a list of co-ordinates 产生随机纬度 - Generate random lat lon 如何在给定时间在大表中查找GPS坐标的接近值 - How to find close GPS co-ordinates in large table at a given time 给定日期时间,计算太阳直接在头顶上方的经纬度坐标 - Given a datetime, calculate the lat/lon coordinates where the sun is directly overhead 给定2-D平面中n个点的坐标,找出形成直角三角形的三元组的数量 - Given the co-ordinates of n points in 2-D plane, find the number of triplets that form right triangle 确定从一个纬度/经度到另一纬度的罗盘方向 - Determine compass direction from one lat/lon to the other 如何从服务器端的客户端计算到给定点的最接近坐标 - How to calculate the closest co-ordinates to a given point from a client on server side 从坐标到坐标的可能路径 - Possible Path from to Co-ordinates 给定定义形状的坐标,是否有任何算法可以计算形状的面积? - Is there any algorithm for calculating area of a shape given co-ordinates that define the shape? 给定地球上2个闭合点的纬度/经度(&lt;10m),如何计算以米为单位的距离? - Given the lat/lon of 2 close points on earth (<10m), How do I calculate the distance in metres?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM