利用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']}









免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM