Created
July 9, 2021 02:27
-
-
Save h1code2/0edbab500f4fb73e26981e5c68c5214a to your computer and use it in GitHub Desktop.
更具经纬度判断国家、城市、城镇 #geopy #经纬度 #国家
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# @Time : 2021/6/30 16:13 | |
# @Author : h1code2 | |
# @File : code.py | |
# @Software: PyCharm | |
# import module | |
from geopy.geocoders import Nominatim | |
# initialize Nominatim API | |
geo_locator = Nominatim(user_agent="GoSpider") | |
# Latitude & Longitude input | |
Latitude = "25.124398793756" | |
Longitude = "62.326154919175" | |
location = geo_locator.reverse(Latitude + "," + Longitude, language="en") | |
address = location.raw['address'] | |
# traverse the data | |
city = address.get('city', '') | |
state = address.get('state', '') | |
country = address.get('country', '') | |
code = address.get('country_code') | |
zipcode = address.get('postcode') | |
print('City : ', city) | |
print('State : ', state) | |
print('Country : ', country) | |
print('Zip Code : ', zipcode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment