Orion's Studio.

在某个经纬度附近

2017/07/15

1纬度居然有111319.5米

直接判断两个经纬度的距离太麻烦了,于是用了个简单的替代方案

根据距离算单位经纬度,在两个经度和两个纬度之间的就算是附近

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public const double DeltLat = 1 / 111319.5;

public static double DeltLong(double lat)
{
return DeltLat / Math.Cos(lat * Math.PI / 180);
}

public static bool IsNearby(double aOriginalLat, double aOriginalLong, double aLat, double aLong, double aDistence)
{
var degreeLat = aDistence * DeltLat;
var degreeLong = aDistence * DeltLong(aOriginalLat);
return aLat < aOriginalLat + degreeLat && aLat > aOriginalLat - degreeLat &&
aLong < aOriginalLong + degreeLong && aLong > aOriginalLong - degreeLong;
}
CATALOG
  1. 1. 1纬度居然有111319.5米
  2. 2. 直接判断两个经纬度的距离太麻烦了,于是用了个简单的替代方案