Skip to content

Instantly share code, notes, and snippets.

@Zsoldier
Created June 29, 2016 18:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Zsoldier/dccc79e1c232f9d6c78b5b72568cb2de to your computer and use it in GitHub Desktop.
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.
#!/usr/bin/python
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(" ", ""))
return
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