Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple Python script that returns city name from provided longitude and latitude variables from bash. Uses geopy module and appears to work both on Python 2 and 3. City return may or may not be accurate. Kind of guessing by selecting 3rd return record from google and selecting first entry in comma separated return. Needs work obviously.
import sys
def cityinfo(lat, lon):
from geopy.geocoders import GoogleV3
locator = GoogleV3()
address = locator.reverse([lat, lon])
city = address[3].address.split(",")[0]
print(city.replace(" ", ""))
cityinfo(sys.argv[1], sys.argv[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.