From 3e1a57da503029533f1597087af7b22400675da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonel=20C=C3=A2mara?= Date: Wed, 13 Aug 2014 15:58:04 +0100 Subject: [PATCH] added a reverse_geocode function to tools --- gluon/tools.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gluon/tools.py b/gluon/tools.py index 4eecfcdd..e06b089a 100644 --- a/gluon/tools.py +++ b/gluon/tools.py @@ -4457,6 +4457,14 @@ def geocode(address): return (0.0, 0.0) +def reverse_geocode(lat, lng, lang=current.T.accepted_language): + """ Try to get an approximate address for a given latitude, longitude. """ + try: + return json_parser.loads(fetch("http://maps.googleapis.com/maps/api/geocode/json?latlng=%(lat)s,%(lng)s&sensor=true/false&language=%(lang)s" % locals()))['results'][0]['formatted_address'] + except: + return '' + + def universal_caller(f, *a, **b): c = f.func_code.co_argcount n = f.func_code.co_varnames[:c]