【问题标题】:Get address from given coordinate using python使用python从给定坐标获取地址
【发布时间】:2020-03-30 10:26:20
【问题描述】:

我有一些经纬度坐标,我想使用 Python 将其转换为特定地址。你知道怎么做吗?谢谢,我是新来的。

【问题讨论】:

标签: visual-studio-code python coordinates street-address


【解决方案1】:

您所说的方法称为反向地理编码。 您可以使用 Nominatim (OSM) 获得免费的地理编码服务

from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="specify_your_app_name_here")
location = geolocator.reverse("52.509669, 13.376294")
print(location.address)

或者如果您想获得更好的结果,您可以使用需要 API Key 的 Google Geocode 服务

from geopy.geocoders import GoogleV3
geolocator = GoogleV3(api_key='Your_API_Key')
location = geolocator.reverse("52.509669, 13.376294")
print(location.address)

【讨论】:

    【解决方案2】:

    使用地理, 这是我自己制作的脚本,你可以使用它

    from geopy.geocoders import Nominatim
    from os import system, name
    

    那些是你的进口。 那么你会想要定义一个清晰的函数,这将在稍后发挥作用

    def clear():
        if name == 'nt':
            _ = system('cls')
        else:
            _ = system('clear')
    

    然后定义用户代理:

    geolocator = Nominatim(user_agent="coordinateconverter")
    

    我将它设置为坐标转换器,因为这是我的项目名称

    然后定义您的地址:

    address = '42.2817131, -83.7465425'
    

    那是安娜堡博物馆地址

    然后实际转换它:

    location = geolocator.reverse(address)
    print(location)
    

    这是未经测试的代码,因此可能无法正常工作,但应该可以

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-26
      • 1970-01-01
      • 2020-10-05
      • 1970-01-01
      • 2020-01-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多