How to get the elevations points from Google maps in C#?

3.6k Views Asked by At

I am trying to get the altitudes of all points in a specific Google Map, be it in the UK or the US or just randomly around the world, and then store the altitude data into an Array[x,y] in C#??

I know that Google has something called Elevation map, but it seems that everyone are trying to get the Longitude / Latitude using it, so.. Can anyone give a link to where I can find how to get the Altitude or give an example program for it in C#??

2

There are 2 best solutions below

1
Jorge On

You need to call the rest service of google which returns the elevations base on direction or coordinates here's some code that could guide you in the right way

 //builds the URL of the service
 String url = "http://maps.google.com/maps/api/elevtation/xml?address=example"; 
 //gets the xml returned by the service
 XmlTextReader xml = new XmlTextReader(url);

From here's you need to parse the xml and store in in whatever element that you want, could be a database, List, Array. etc.

Here you will found how to call service and all the different ways to consume the service and see which part you need

0
Jimbo On
using Newtonsoft.Json.Linq;


    public double getElevation(DbGeography point)
    {
        //https://developers.google.com/maps/documentation/elevation/intro
        var request = (HttpWebRequest)WebRequest.Create(string.Format("https://maps.googleapis.com/maps/api/elevation/json?locations={0},{1}", point.Latitude, point.Longitude));
        var response = (HttpWebResponse)request.GetResponse();
        var sr = new StreamReader(response.GetResponseStream() ?? new MemoryStream()).ReadToEnd();

        var json = JObject.Parse(sr);
        return (double)json.SelectToken("results[0].elevation");
    }