Skip to content

Instantly share code, notes, and snippets.

@liquidgenius
Forked from bitner/plpython - geopy geocode
Created August 8, 2020 14:29
Show Gist options
  • Save liquidgenius/4f1155fa2c1c7381bba0f426dd11cf36 to your computer and use it in GitHub Desktop.
Save liquidgenius/4f1155fa2c1c7381bba0f426dd11cf36 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