利用python解析地址经纬度和利用经纬度定位地址

解析地址经纬度

from geopy.geocoders import Nominatim
try:
    geolocator = Nominatim()
    location = geolocator.geocode("NYU Shanghai")
    print(location.address)
    print((location.latitude, location.longitude))
    print(location.raw)
except:
    print('not found')

结果如下:

{'place_id': '146818865', 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', 'osm_type': 'way', 'osm_id': '307821899', 'boundingbox': ['31.2274081', '31.2283654', '121.5291039', '121.5303289'], 'lat': '31.22789385', 'lon': '121.529716424151', 'display_name': 'NYU Shanghai, 1555, 世纪大道, 洋泾街道, 浦东新区, 上海市, 200120, 中国', 'class': 'amenity', 'type': 'university', 'importance': 0.201, 'icon': 'https://nominatim.openstreetmap.org/images/mapicons/education_university.p.20.png'}

反向解析

try:
    geolocator = Nominatim()
    location = geolocator.reverse("31.2284923, 121.402113889769")
    print(location.address)
    print((location.latitude, location.longitude))
    print(location.raw)

except:
    print('not found')

结果如下

华东师范大学, 3663, 中山北路, 曹家渡, 普陀区, 普陀区 (Putuo), 上海市, 200062, 中国 (31.2284923, 121.402113889769) {'place_id': '199368033', 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', 'osm_type': 'relation', 'osm_id': '6179557', 'lat': '31.2284923', 'lon': '121.402113889769', 'display_name': '华东师范大学, 3663, 中山北路, 曹家渡, 普陀区, 普陀区 (Putuo), 上海市, 200062, 中国', 'address': {'university': '华东师范大学', 'house_number': '3663', 'road': '中山北路', 'suburb': '曹家渡', 'city': '普陀区', 'county': '普陀区 (Putuo)', 'state': '上海市', 'postcode': '200062', 'country': '中国', 'country_code': 'cn'}, 'boundingbox': ['31.2234204', '31.233672', '121.3973669', '121.4061896']}








原文地址:https://www.cnblogs.com/oikoumene/p/10077444.html