【问题标题】:Google Map API : Route with more than one transport modeGoogle Map API:具有多种运输方式的路线
【发布时间】:2016-07-01 22:13:57
【问题描述】:

我在 Google 地图中有一个要求。我有起点和终点。在它们之间,几乎没有航点。我必须通过航路点连接起点和终点。这对于谷歌地图 api 是可行的,我已经做到了。但是在一种情况下,我必须绘制铁路路线,即两个航点将通过铁路路线连接。所以,我有一条由汽车路线和铁路路线组成的路线。

示例:考虑 A、B、C 和 D 是地点。

A - 起点,B- 航点 1,C - 航点 2,D - 终点

A 到 B - 汽车路线

B 到 C - 铁路路线

C 到 D - 汽车路线

我该怎么做??

请指导我。!!

【问题讨论】:

标签: javascript api google-maps


【解决方案1】:

我希望这个例子对你有用并且必须注册 YOUR_API_KEY更改您的位置纬度和经度flightPlanCoordinates javascript变量值

https://developers.google.com/maps/documentation/javascript/examples/polyline-simple?authuser=2

   <!DOCTYPE html>
    <html>
      <head>
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
        <meta charset="utf-8">
        <title>Simple Polylines</title>
        <style>
          html, body {
            height: 100%;
            margin: 0;
            padding: 0;
          }
          #map {
            height: 100%;
          }
        </style>
      </head>
      <body>
        <div id="map"></div>
        <script>

          // This example creates a 2-pixel-wide red polyline showing the path of William
          // Kingsford Smith's first trans-Pacific flight between Oakland, CA, and
          // Brisbane, Australia.

          function initMap() {
            var map = new google.maps.Map(document.getElementById('map'), {
              zoom: 3,
              center: {lat: 0, lng: -180},
              mapTypeId: google.maps.MapTypeId.TERRAIN
            });

            var flightPlanCoordinates = [
              {lat: 37.772, lng: -122.214},
              {lat: 21.291, lng: -157.821},
              {lat: -18.142, lng: 178.431},
              {lat: -27.467, lng: 153.027}
            ];
            var flightPath = new google.maps.Polyline({
              path: flightPlanCoordinates,
              geodesic: true,
              strokeColor: '#FF0000',
              strokeOpacity: 1.0,
              strokeWeight: 2
            });

            flightPath.setMap(map);
          }
        </script>
        <script async defer
        src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">
        </script>
      </body>
    </html>

【讨论】:

  • 对不同的路段分别提出请求(路线请求只能有一种出行模式)
  • @geocodezip 我只有两个坐标,起点和终点。我需要在海中画一条线的中间点。你能给我一些想法来获得它们吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-22
  • 2011-08-04
相关资源
最近更新 更多