javascript - 谷歌地图根据海拔绘制路线

标签 javascript google-maps google-maps-api-3 google-elevation-api

我对此很陌生,对我来说看起来很有趣。有没有办法根据海拔限制在点 A 和点 B 之间创建路线。我正在尝试将其用于飞机,因此不需要遵循任何道路:)

即: 海拔限制:200米

pointA: 38°44′50″N , 090°21′41″W - 圣路易斯机场

pointB: 39°02′56″N , 084°40′04″W - 辛辛那提机场

如何在不超过海拔限制的情况下绘制从 A 点到 B 点的路线?

提前致谢...

$(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>

最佳答案

目前无法让 Google map 计算出不超过指定海拔限制的路线。

这适用于:

现在可用的是请求指定位置的高程数据,以及在给定分辨率下与此指定位置一起的附加高程数据(例如,当指定 2 个位置时,samples=3 将导致两个端点和中点的高程数据)。

所以理论上是可以的

  1. 用“大量样本”计算路线,
  2. 根据海拔限制评估响应,
  3. 如果某一点超过海拔限制,请更改路线,
  4. 并一遍又一遍地开始程序,直到不再超过海拔限制。

这可能是一项昂贵的任务,具体取决于海拔限制本身和距离。


引用: 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.


脚注/提示

我建议查看其他 API(例如 OpenStreetMap)。也许有一个 API 可以提供基于海拔的路线计算。

如果前端需要 Google Maps UI,则检索到的路线可能会传输到 Google Maps(这将是最简单的部分)。

关于javascript - 谷歌地图根据海拔绘制路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46061385/

相关文章:

android 应用无法获取连接工厂客户端

javascript - 使用XMLHttpRequest加载KML谷歌地图,无法加载KML

javascript - 谷歌地图在 Bootstrap 模态中的位置总是偏离 map 大小宽度和高度

JavaScript 错误 : Uncaught ReferenceError: marker1 is not defined

javascript - Google map API v3 - 信息窗口未呈现的多个标记

javascript - 在 Qualtrics 中将键盘使用与答案随机化集成

javascript - 如何使用文档的ID从mongoDB集合中删除文档?

google-maps - Google map v3,带有文本框的自定义控件 : can't perform input

javascript - 如何在 Angular js 中将 JSON 嵌套字典转换为 JSON 嵌套数组?

javascript - jQuery 动画 Div 滚动器