Skip to content

Instantly share code, notes, and snippets.

@RameshKamath
Forked from Alliages/elevation.py
Last active April 12, 2018 08:41
Show Gist options
  • Save RameshKamath/bb7fdb9efdedb15deab60665db82c3aa to your computer and use it in GitHub Desktop.
Save RameshKamath/bb7fdb9efdedb15deab60665db82c3aa to your computer and use it in GitHub Desktop.

Revisions

  1. RameshKamath revised this gist Apr 12, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion elevation_google_maps_API.py
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@
    # @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>
    #
    # EXAMPLE :
    # print elevation(48.8445548,2.4222176)
    # print(elevation(48.8445548,2.4222176))

    from __future__ import print_function
    import json
  2. RameshKamath renamed this gist Apr 12, 2018. 1 changed file with 8 additions and 6 deletions.
    14 changes: 8 additions & 6 deletions elevation.py → elevation_google_maps_API.py
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,9 @@
    #
    # elevation: A very simple python script that get elevation from latitude and longitude with google maps API by Guillaume Meunier
    # elevation_google_maps: A very simple python script that get elevation from latitude and longitude with google maps API by Guillaume Meunier
    # -- with edits from Ramesh Kamath <[email protected]>
    #
    # -----------------------------------
    # NO DEPENDANCIES except JSON and URLLIB
    # NO DEPENDANCIES except JSON and REQUESTS
    # -----------------------------------
    #
    # Copyright (c) 2016, Guillaume Meunier <[email protected]>
    @@ -26,19 +27,20 @@

    from __future__ import print_function
    import json
    import urllib
    import requests

    def elevation(lat, lng):
    apikey = "USE YOUR OWN KEY !!!"
    url = "https://maps.googleapis.com/maps/api/elevation/json"
    request = urllib.urlopen(url+"?locations="+str(lat)+","+str(lng)+"&key="+apikey)
    request = requests.get(url+"?locations="+str(lat)+","+str(lng)+"&key="+apikey)
    try:
    results = json.load(request).get('results')
    results = json.loads(request.text).get('results')
    if 0 < len(results):
    elevation = results[0].get('elevation')
    #resolution = results[0].get('resolution') # for RESOLUTION
    # ELEVATION
    return elevation
    else:
    print('HTTP GET Request failed.')
    except ValueError as e:
    print('JSON decode failed: '+str(request))
    print('JSON decode failed: '+str(request) + str(e))
  3. RameshKamath revised this gist Apr 12, 2018. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions elevation.py
    Original file line number Diff line number Diff line change
    @@ -24,6 +24,7 @@
    # EXAMPLE :
    # print elevation(48.8445548,2.4222176)

    from __future__ import print_function
    import json
    import urllib

    @@ -38,6 +39,6 @@ def elevation(lat, lng):
    # ELEVATION
    return elevation
    else:
    print 'HTTP GET Request failed.'
    except ValueError, e:
    print 'JSON decode failed: '+str(request)
    print('HTTP GET Request failed.')
    except ValueError as e:
    print('JSON decode failed: '+str(request))
  4. @Alliages Alliages created this gist Apr 28, 2016.
    43 changes: 43 additions & 0 deletions elevation.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    #
    # elevation: A very simple python script that get elevation from latitude and longitude with google maps API by Guillaume Meunier
    #
    # -----------------------------------
    # NO DEPENDANCIES except JSON and URLLIB
    # -----------------------------------
    #
    # Copyright (c) 2016, Guillaume Meunier <[email protected]>
    # GEOJSON_export is free software; you can redistribute it and/or modify
    # it under the terms of the GNU General Public License as published
    # by the Free Software Foundation; either version 3 of the License,
    # or (at your option) any later version.
    #
    # GEOJSON_export is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    # GNU General Public License for more details.
    #
    # You should have received a copy of the GNU General Public License
    # along with GEOJSON_export; If not, see <http://www.gnu.org/licenses/>.
    #
    # @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>
    #
    # EXAMPLE :
    # print elevation(48.8445548,2.4222176)

    import json
    import urllib

    def elevation(lat, lng):
    apikey = "USE YOUR OWN KEY !!!"
    url = "https://maps.googleapis.com/maps/api/elevation/json"
    request = urllib.urlopen(url+"?locations="+str(lat)+","+str(lng)+"&key="+apikey)
    try:
    results = json.load(request).get('results')
    if 0 < len(results):
    elevation = results[0].get('elevation')
    # ELEVATION
    return elevation
    else:
    print 'HTTP GET Request failed.'
    except ValueError, e:
    print 'JSON decode failed: '+str(request)