Ben*_*ate 73 algorithm geolocation
我想基于坐标和以米为单位的距离创建2个新经度和2个新纬度,我想在某个点周围创建一个漂亮的边界框.这是一个城市的一部分,最大±1500米.因此,我不认为必须考虑地球的曲率.
所以我有50.0452345(x)和4.3242234(y),我想知道x + 500米,x - 500米,y - 500米,y + 500米
我发现了许多算法,但几乎所有算法似乎都在处理点之间的距离.
nib*_*bot 107
每度经度的公里数约为
(2*pi/360) * r_earth * cos(theta)
Run Code Online (Sandbox Code Playgroud)
theta纬度在哪里,r_earth大约是6378公里.
每个纬度的公里数在所有位置大致相同,大约相同
(2*pi/360) * r_earth = 111 km / degree
Run Code Online (Sandbox Code Playgroud)
所以你可以这样做:
new_latitude = latitude + (dy / r_earth) * (180 / pi);
new_longitude = longitude + (dx / r_earth) * (180 / pi) / cos(latitude * pi/180);
Run Code Online (Sandbox Code Playgroud)
只要dx和dy地球半径相比较小,你就不会太靠近极地.
Num*_*lan 24
接受的答案是完全正确和有效的.我做了一些调整,然后变成了这个:
double meters = 50;
// number of km per degree = ~111km (111.32 in google maps, but range varies
between 110.567km at the equator and 111.699km at the poles)
// 1km in degree = 1 / 111.32km = 0.0089
// 1m in degree = 0.0089 / 1000 = 0.0000089
double coef = meters * 0.0000089;
double new_lat = my_lat + coef;
// pi / 180 = 0.018
double new_long = my_long + coef / Math.cos(my_lat * 0.018);
Run Code Online (Sandbox Code Playgroud)
希望这也有帮助.
sst*_*ten 13
对于纬度做:
var earth = 6378.137, //radius of the earth in kilometer
pi = Math.PI,
m = (1 / ((2 * pi / 360) * earth)) / 1000; //1 meter in degree
var new_latitude = latitude + (your_meters * m);
Run Code Online (Sandbox Code Playgroud)
对于经度做:
var earth = 6378.137, //radius of the earth in kilometer
pi = Math.PI,
cos = Math.cos,
m = (1 / ((2 * pi / 360) * earth)) / 1000; //1 meter in degree
var new_longitude = longitude + (your_meters * m) / cos(latitude * (pi / 180));
Run Code Online (Sandbox Code Playgroud)
变量your_meters可以包含正值或负值.
你有没有检查过:如何找到给定纬度/长度以北x km的纬度/经度?
这些计算充其量是烦人的,我做了很多.thersineine公式将是你的朋友.
一些参考:http://www.movable-type.co.uk/scripts/latlong.html
我不得不花费大约两个小时来解决 @nibot 的解决方案,我只需要一种方法来创建边界框给定其中心点和宽度/高度(或半径)(以公里为单位):
我不完全理解数学/地理上的解决方案。我调整了解决方案(通过尝试和错误)以获得四个坐标:
北:
private static Position FromKmToNPosition(Position p, double km)
{
double r_earth = 6378;
var pi = Math.PI;
var new_latitude = p.Lat + (km / r_earth) * (180 / pi);
return new Position(new_latitude, p.Long);
}
Run Code Online (Sandbox Code Playgroud)
东:
private static Position FromKmToEPosition(Position p, double km)
{
double r_earth = 6378;
var pi = Math.PI;
var new_longitude = p.Long + (km / r_earth) * (180 / pi) / Math.Cos(p.Lat * pi / 180);
return new Position(p.Lat, new_longitude);
}
Run Code Online (Sandbox Code Playgroud)
南:
private static Position FromKmToSPosition(Position p, double km)
{
double r_earth = 6378;
var pi = Math.PI;
var new_latitude = p.Lat - (km / r_earth) * (180 / pi);
return new Position(new_latitude, p.Long);
}
Run Code Online (Sandbox Code Playgroud)
西:
private static Position FromKmToWPosition(Position p, double km)
{
double r_earth = 6378;
var pi = Math.PI;
var new_longitude = p.Long - (km / r_earth) * (180 / pi) / Math.Cos(p.Lat * pi / 180);
return new Position(p.Lat, new_longitude);
}
Run Code Online (Sandbox Code Playgroud)
为了完整起见发布此方法。
“按原样”使用此方法可以:
将任意点移动定义米的 Python 方法。
def translate_latlong(lat,long,lat_translation_meters,long_translation_meters):
''' method to move any lat,long point by provided meters in lat and long direction.
params :
lat,long: lattitude and longitude in degrees as decimal values, e.g. 37.43609517497065, -122.17226450150885
lat_translation_meters: movement of point in meters in lattitude direction.
positive value: up move, negative value: down move
long_translation_meters: movement of point in meters in longitude direction.
positive value: left move, negative value: right move
'''
earth_radius = 6378.137
#Calculate top, which is lat_translation_meters above
m_lat = (1 / ((2 * math.pi / 360) * earth_radius)) / 1000;
lat_new = lat + (lat_translation_meters * m_lat)
#Calculate right, which is long_translation_meters right
m_long = (1 / ((2 * math.pi / 360) * earth_radius)) / 1000; # 1 meter in degree
long_new = long + (long_translation_meters * m_long) / math.cos(lat * (math.pi / 180));
return lat_new,long_new
Run Code Online (Sandbox Code Playgroud)