1

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
    Welcome to Stack Overflow - nice to have you. Please read [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) and [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) to help keeping Stack Overflows content on the highest possible level and increase your chances getting an appropriate answer. You have to show what you have done so far which normaly includes some code... – Axel Sep 05 '17 at 18:48
  • 1
    @Axel I haven't done anything so far :) I could put an example of simple polyline between 2 points but it wouldn't help I guess. That is why I didn't add anything else besides the question. –  Sep 05 '17 at 18:52
  • 1
    @Axel I added a basic snippet. What does it have to do with possible duplicate question you mentioned in your last comment. I am trying to draw shortest route based on elevation restriction. I guess you didn't understand what I was asking for –  Sep 05 '17 at 19:45
  • 1
    @Axel yes I did:) Couldn't find a solution or example about my question. That is why I am asking this question. There are examples about elevation of points but my question is how can I draw route between 2 points without exceeding elevation limit. Do you have any idea how? –  Sep 05 '17 at 19:56
  • 1
    I cannot chat bc my reputation is only 2 :) –  Sep 05 '17 at 20:08
  • No, if I would know , then I would have the answer I guess :) –  Sep 05 '17 at 20:12
  • I'll clear my comments and downvote now that you have shown some effort - **its a nice and interesting question indeed**. Sorry dianoche but I saw a lot of questions where somebody was really just too lazy and they all looked a bit like your - no samples, norefs - you know. Keep that in mind for your next question... *Maybe would be helpful for others if you also list the reference link?* – Axel Sep 05 '17 at 20:18
  • Hey @dianoche, maybe it is not satisfying. But its the correct answer I guess. Maybe the "Footnote / Hint" at the end of my answer will take you further! – Axel Sep 05 '17 at 22:01

1 Answers1

1

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).

Axel
  • 3,331
  • 11
  • 35
  • 58