Calling Google API for elevation data using python 3

Hi all,

I am trying to retrieve the elevation data of a specific lat-long using python code in grasshopper-ghpython 3. I have tried it in vscode and it is working with package requests.

Thanks in advance
Vijesh

I think this is the solution.

As a substitute of the requests module you could use the urllib.requests module

import urllib.request

def get_elevation(lat, lon):
    url = f"https://api.opentopodata.org/v1/test-dataset?locations={lat},{lon}"
    res = urllib.request.urlopen(url)

if __name__ == "__main__":
    get_elevation(lat=37.7749, lon=-122.4194)

Result:

{
    "results": [
        {
            "dataset": "test-dataset",
            "elevation": -142.42425537109375,
            "location": {
                "lat": 37.7749,
                "lng": -122.4194
            }
        }
    ],
    "status": "OK"
}

2 Likes