从旧+ n米计算新的经度,纬度

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)

只要dxdy地球半径相比较小,你就不会太靠近极地.

  • @josch:好抓.尝试下次回答答案,而不是简单地提出修正.很多人只是从StackOverflow复制并粘贴代码,认为它是正确的并且可以使用. (7认同)
  • 好的,方向是什么?我的意思是,如果我想加50米,它会被添加到哪里?右,左,上,下? (3认同)
  • 地球不是完美的球形,因此使用"半径"的单个值是近似值.维基百科说"从地面上的点到中心的距离从6,353公里到6,384公里".它还说"几种不同的地球建模方法,每个平均半径为6,371 km",这表明了你的价值.实际上,如果这种修正在您的应用程序中很重要,那么您应该使用更好的算法. (3认同)
  • 对于那些不确定r_earth变量应该以米为单位并且应该等于大约6371000.0的人 (3认同)
  • 要计算新经度而不是纬度,应使用新纬度:new_longitude = longitude + (dx / r_earth) * (180 / pi) / cos(NEW_LATITUDE * pi/180); (3认同)
  • 从度数转换为弧度你用py乘以并除以180.但你写的是'cos(纬度*180/pi)` (2认同)

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)

希望这也有帮助.

  • `0.0000089`?尽量避免神奇的数字,没有人会理解这一点. (25认同)
  • 如果没有人知道如何重现这个数字,那仍然是神奇的.为什么不将完整的计算放入代码中? (15认同)
  • 谷歌地图1度等于111.32公里.1Degree = 111.32KM.1KM in Degree = 1/111.32 = 0.008983.1M度= 0.000008983. (11认同)
  • 您应该在答案中发表评论,将其放在评论中是没有用的. (6认同)
  • 它是代码中地球直径和pi数字的简短版本.不是魔法. (2认同)
  • @Muhammad Azeem我有同样的问题使用这个公式我可以得到一个新的lat和一个新的长在一个方向,如何获得另一个方向? (2认同)

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可以包含正值或负值.


Rya*_*ier 7

你有没有检查过:如何找到给定纬度/长度以北x km的纬度/经度

这些计算充其量是烦人的,我做了很多.thersineine公式将是你的朋友.

一些参考:http://www.movable-type.co.uk/scripts/latlong.html


msh*_*hwf 5

我不得不花费大约两个小时来解决 @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)


san*_*ign 5

为了完整起见发布此方法。

“按原样”使用此方法可以:

  • 在任一轴上将任何(纬度、经度)点移动给定米。

将任意点移动定义米的 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)