[英]C# Find Midpoint of two Latitude / Longitudes
I need to find the midpoint between two Latitude/Longitude points. 我需要找到两个纬度/经度点之间的中点。
I am trying to center a map between two locations I have plotted and need to find that point. 我试图将我绘制的两个位置之间的地图居中,并且需要找到该点。
I have written this function from other examples I have found and it doesn't seem to work. 我已经从我找到的其他示例中编写了这个函数,但似乎没有用。
public static void midPoint(double lat1, double lon1, double lat2, double lon2, out double lat3_OUT, out double lon3_OUT)
{
//http:// stackoverflow.com/questions/4656802/midpoint-between-two-latitude-and-longitude
double dLon = DistanceAlgorithm.Radians(lon2 - lon1);
//convert to radians
lat1 = DistanceAlgorithm.Radians(lat1);
lat2 = DistanceAlgorithm.Radians(lat2);
lon1 = DistanceAlgorithm.Radians(lon1);
double Bx = Math.Cos(lat2) * Math.Cos(dLon);
double By = Math.Cos(lat2) * Math.Sin(dLon);
double lat3 = Math.Atan2(Math.Sin(lat1) + Math.Sin(lat2), Math.Sqrt((Math.Cos(lat1) + Bx) * (Math.Cos(lat1) + Bx) + By * By));
double lon3 = lon1 + Math.Atan2(By, Math.Cos(lat1) + Bx);
lat3_OUT = lat3;
lon3_OUT = lon3;
}
Here is an example output. 这是一个示例输出。
lat1 37.7977008
lat2 37.798392
lon1 -122.1637914
lon2 -122.161464
lat3 0.65970036060147585
lon3 -2.1321400763480485
See Lat3 and Lon3. 见Lat3和Lon3。
Thanks! 谢谢!
It appears that your output is correct , except that it is in radians and you are expecting degrees ? 看来你的输出是正确的 , 除了它是弧度并且你期望度数 ? you may need to convert from radian to degrees to meet the expected output. 您可能需要从弧度转换为度数以满足预期输出。
-(2.1321400763480485 radians) = -122.162628 degrees
0.65970036060147585 radians = 37.7980464 degrees
It looks like you are already using the great-circle algorithm that Jon Martin and IanDotKelly mentioned. 看起来你已经在使用Jon Martin和IanDotKelly提到的大圆算法了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.