Google maps draw route based on elevation

829 views Asked by At

I am very new to this and looks very interesting to me. Is there a way to create route between pointA and pointB based on elevation restriction. I am trying to use this for planes so doesn't need to follow any roads :)

IE: Elevation limit: 200 meters

pointA: 38°44′50″N , 090°21′41″W - Saint Louis Airport

pointB: 39°02′56″N , 084°40′04″W - Cincinnati Airport

How can I draw a route from pointA to pointB without exceeding elevation limit?

Thanks in advance...

$(document).ready(function() {
 var path = [
      {lat: 38.74722222, lng: -90.36138889},  // St Louis
      {lat: 39.04888889, lng: -84.66777778}];  // Cincinnati

  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 6,
    maxZoom: 8,
    minZoom: 1,
    streetViewControl: false,
    center: path[1],
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });
  
var flightPath = new google.maps.Polyline({
          path: path,
          geodesic: true,
          strokeColor: '#FF0000',
          strokeOpacity: 1.0,
          strokeWeight: 2
        });

        flightPath.setMap(map);
 
});
html,
body,
#map {
  height: 100%;
  width: 100%;
  padding: 0px;
  margin: 0px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map"></div>

1

There are 1 answers

0
Axel On

By now it is not possible to let Google Maps calculate a route that does not exceed a specfied elevation limit.

This applies to both:

What is available by now is to request elevation data for specified locations and in addition elevation data alongside this specified locations in a given resolution (eg when 2 locations are specified then samples=3 will result in elevation data for the two endpoints and the halfway point).

So theoretically it is possible to

  1. calculate a route with "a lot of samples",
  2. evaluate the response against the elevation limit,
  3. change the route if elevation limit is exceeded at one point,
  4. and start procedure over and over again until the elevation limit does not exceed anymore.

This might be an expensive task depending on the elevation limit itself and the distance as well.


Reference: https://developers.google.com/maps/documentation/elevation/intro

The Google Maps Elevation API returns data for single point queries of the highest accuracy possible. Batch queries involving multiple locations may return data with less accuracy, especially if the locations are spread apart, as some smoothing of data occurs.
[...]
Sampled Path Requests
- path (required) defines a path on the earth for which to return elevation data. This parameter defines a set of two or more ordered {latitude,longitude} pairs defining a path along the surface of the earth. This parameter must be used in conjunction with the samples parameter described below. For more information, see Specifying Paths below.
- samples (required) specifies the number of sample points along a path for which to return elevation data. The samples parameter divides the given path into an ordered set of equidistant points along the path.


Footnote / Hint

I would suggest to have a look at other APIs (eg OpenStreetMap). Maybe there is an API that provides the calculation of a route based on elevation.

If Google Maps UI is wanted on frontend the retrieved route might be transferred to Google Maps (which would be the easiest part).