使用 python 从给定坐标获取地址

Get address from given coordinate using python

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

您所说的方法称为反向地理编码。 您可以使用 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 键

的 Google 地理编码服务
from geopy.geocoders import GoogleV3
geolocator = GoogleV3(api_key='Your_API_Key')
location = geolocator.reverse("52.509669, 13.376294")
print(location.address)

使用geopy, 这是我自己写的脚本,你可以用

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)

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