From 0dafa16958a8340ee60a2d7d478ec002fda35f9c Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 25 Jul 2018 12:01:27 +0000 Subject: [PATCH] Added get_elevation_from_latlng method to Google Maps plugin --- platypush/plugins/google/maps.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/platypush/plugins/google/maps.py b/platypush/plugins/google/maps.py index c636021a..a4ac3b49 100644 --- a/platypush/plugins/google/maps.py +++ b/platypush/plugins/google/maps.py @@ -68,6 +68,31 @@ class GoogleMapsPlugin(GooglePlugin): return address + @action + def get_elevation_from_latlng(self, latitude, longitude): + """ + Get the elevation in meters of a geo point given lat/long + + :param latitude: Latitude + :type latitude: float + + :param longitude: Longitude + :type longitude: float + """ + + response = requests.get('https://maps.googleapis.com/maps/api/elevation/json', + params = { + 'locations': '{},{}'.format(latitude, longitude), + 'key': self.api_key, + }).json() + + elevation = None + + if response.get('results'): + elevation = response['results'][0]['elevation'] + + return { 'elevation': elevation } + # vim:sw=4:ts=4:et: