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)!