C# 已知经纬度计算两点距离函数
public Task<double> GetDistance(double lat1, double lon1, double lat2, double lon2) { int R = 6371; double rLat1 = ToRadian(lat1); double rLat2 = ToRadian(lat2); double dLat = rLat2 - rLat1; double dLon = ToRadian(lon2 - lon1); double a = Math.Pow(Math.Sin(dLat / 2), 2) + Math.Pow(Math.Sin(dLon / 2), 2) * Math.Cos(rLat1) * Math.Cos(rLat2); double b = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); return Task.FromResult((R * b)); }
以上就是C# 已知经纬度计算两点距离函数的内容,更多相关内容请关注PHP中文网(www.php.cn)!