I had done this program that takes an input from STDIN and processes it to check if it is a Latitude/longitude combo or a place's name. Then it uses geocoding and returns an address corresponding to the latitude longitude or returns a latitude and longitude if the input is an address. I am using Nomatim, I would like to know how else can we do this?I would also like to know how I can make the code better.
from geopy.geocoders import Nominatim
import re
geolocator=Nominatim()
arg=raw_input()
pattern=re.compile(r'^(\-?\d+(\.\d+)?),\s*(\-?\d+(\.\d+)?)$')
if pattern.match(arg):
loc=geolocator.reverse(arg)
if loc is not None:
print(loc.address)
print(loc.latitude, loc.longitude)
else:
print "the location doesnt exist"
else:
loc=geolocator.geocode(arg)
if loc is not None:
print(loc.address)
print(loc.latitude, loc.longitude)
else:
print "This address does not exist"