private const double EARTH_RADIUS = 6378.137;//地球半径
private static double RAD = Math.PI / 180.0;
//获取两个经纬度之间的距离
public static double GetDistance(double lng1, double lat1, double lng2, double lat2)
{
double radLat1 = lat1 * RAD;
double radLat2 = lat2 * RAD;
double a = radLat1 - radLat2;
double b = (lng1 - lng2) * RAD;
double s = 2 * Math.Sin(Math.Sqrt(Math.Pow(Math.Sin(a / 2), 2) +
Math.Cos(radLat1) * Math.Cos(radLat2) * Math.Pow(Math.Sin(b / 2), 2)));
s = s * EARTH_RADIUS;
s = Math.Round(s * 10000) / 10000;
return s;
}
//获取两个经纬度的某个范围内的最大经度和最大纬度 单位 米
public static double[] getAround(double lat, double lon, int raidus)
{
double PI = 3.14159265;
Double latitude = lat;
Double longitude = lon;
Double degree = (24901 * 1609) / 360.0;
double raidusMile = raidus;
Double dpmLat = 1 / degree;
Double radiusLat = dpmLat * raidusMile;
Double minLat = latitude - radiusLat;
Double maxLat = latitude + radiusLat;
Double mpdLng = degree * Math.Cos(latitude * (PI / 180));
Double dpmLng = 1 / mpdLng;
Double radiusLng = dpmLng * raidusMile;
Double minLng = longitude - radiusLng;
Double maxLng = longitude + radiusLng;
return new double[] { minLat, minLng, maxLat, maxLng };
}
经纬度 范围 距离 计算