【问题标题】:GMaps.js : Trace route between two markers set by geocodingGMaps.js:通过地理编码设置的两个标记之间的跟踪路线
【发布时间】:2012-08-06 16:44:15
【问题描述】:

我正在使用这个:http://hpneo.github.com/gmaps/examples.html

我有两个输入,我在其中放置了一个地址,并且我想追踪两点之间的路线。我可以添加两个标记,但我不知道如何绘制路线。

你知道怎么做吗?

谢谢!

这是我的代码...

    GMaps.geocode({
      address: address_from,
      callback: function(results, status) {
        if (status == 'OK') {
          var address_from = results[0].geometry.location;
          map.addMarker({
            lat: address_from.lat(),
            lng: address_from.lng()
          });
        }
      }       
    });

    GMaps.geocode({
      address: address_to,
      callback: function(results, status) {
        if (status == 'OK') {
          var address_to = results[0].geometry.location;
          map.addMarker({
            lat: address_to.lat(),
            lng: address_to.lng()
          });
        }
      }
    });

    map.drawRoute({
      origin: [address_from.lat(), address_from.lng()],
      destination: [address_to.lat(), address_to.lng()],
      travelMode: 'driving',
      strokeColor: '#131540',
      strokeOpacity: 0.6,
      strokeWeight: 6
    });

【问题讨论】:

  • 不是您要的,但使用 Google Maps API 可以很容易地直接做到这一点
  • 你在哪里看到 drawRoute() 方法?您是否使用了一些您未提及的第三方软件?

标签: jquery google-maps google-maps-api-3 geocode


【解决方案1】:

This example 来自此similar question 通过单击获取放置在地图上的两个标记之间的方向(直接使用 Google Maps API v3)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-31
    • 1970-01-01
    • 2015-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多