【问题标题】:how to add 500meters to a lat and long in Python如何在 Python 中将 500 米添加到纬度和经度
【发布时间】:2022-12-05 21:52:22
【问题描述】:

如果这是初

Latitude:  13.050249
Longitude:  77.462143

如何将纬度和经度增加 500m 并获得新的像素/网格坐标?

【问题讨论】:

  • 这是一个已经完全回答的问题。请查找,如果此类问题已经存在而不是创建一个新问题。并请在您的问题中添加更多信息。你指的是哪个网格?看这里:Calculating new longitude, latitude from old + n meters
  • 没有声明,500 米必须在哪个方向添加,无法回答。其他基本事实也缺失(地球、月球、木星……)。这里的“像素”是什么意思?

标签: python latitude-longitude google-latitude


【解决方案1】:

这是一个函数,您可以传递 x 和 y 来获取纬度和经度。

from math import cos
from math import radians
def meters_2_lat_lon(m, orig_lat):
    lat = m/111111
    lon = m/(111111 * cos(radians(orig_lat)))
    return lat, lon

【讨论】:

    【解决方案2】:

    要使用 haversine 库在 Python 中将纬度和经度增加 500 米,您可以使用 haversine() 函数。此函数根据经纬度坐标计算球体(在本例中为地球)上两点之间的距离。

    以下是如何使用 haversine() 函数将纬度和经度增加 500 米的示例:

    from haversine import haversine
    
    # define the starting latitude and longitude
    lat1 = 52.507538
    lon1 = 13.424073
    
    # define the distance to add in meters
    distance = 500
    
    # calculate the ending latitude and longitude
    lat2, lon2 = haversine(lat1, lon1, distance)
    

    此代码将使用 haversine() 函数计算距离起始纬度和经度 500 米的结束纬度和经度。 haversine() 函数使用 haversine 公式来计算球体上两点之间的距离,这样得到的坐标将精确到几米以内。

    如果要在特定方向(例如北、南、东、西)的经纬度上增加 500 米,可以使用 haversine() 函数的航向参数来指定方向。航向参数接受以度为单位的值,0 度代表北,90 度代表东,180 度代表南,270 度代表西。

    from haversine import haversine
    
    # The latitude and longitude of the starting point
    lat1 = 52.2296756
    lon1 = 21.0122287
    
    # The bearing (i.e., the direction) in which you want to move in degrees (0 degrees representing north, 90 degrees representing east, 180 degrees representing south, and 270 degrees representing the west)
    
    bearing = 45
    
    # The distance in meters that you want to add to the starting point
    distance = 500
    
    # Calculate the new latitude and longitude using the haversine formula
    # and the specified bearing
    new_lat, new_lon = haversine(lat1, lon1, bearing, distance)
    
    # Print the new latitude and longitude
    print(new_lat, new_lon)
    

    【讨论】:

    • 这是您从 AI 生成器复制的另一个答案。这是不受欢迎的,可能会让你很快被禁止
    猜你喜欢
    • 2013-11-17
    • 2013-02-21
    • 1970-01-01
    • 2011-07-06
    • 1970-01-01
    • 2010-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多