Skip to content

Instantly share code, notes, and snippets.

@bitner
Last active August 8, 2020 14:29
Show Gist options
  • Save bitner/7d1f4926c497e19f3bdf to your computer and use it in GitHub Desktop.
Save bitner/7d1f4926c497e19f3bdf to your computer and use it in GitHub Desktop.
CREATE OR REPLACE FUNCTION public.geocode_google(IN inaddress text, OUT address text, OUT longitude double precision, OUT latitude double precision)
RETURNS record AS
$BODY$
from geopy.geocoders import GoogleV3
geolocator = GoogleV3()
try:
address, (latitude, longitude) = geolocator.geocode(inaddress,timeout=1,exactly_one=True)
return address, longitude, latitude
except:
return None, None, None
$BODY$
LANGUAGE plpythonu VOLATILE
COST 100;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment