在我的Google地图代码中,我可以在路线中添加旅行模式吗?

时间:2013-06-01 00:22:12

标签: google-maps mode directions

我有自定义地图上的指示。但是我希望添加我在Google开发者网站上找到的下拉菜单,它允许选择“自行车”,“驾驶”,“过境”,“步行”。


这是我调用函数的代码,我不知道它们在哪里:

var map;
var gdir;
var geocoder = null;
var addressMarker;

function initialize() {
  if (GBrowserIsCompatible()) {      
    map = new GMap2(document.getElementById("map_canvas"));
    gdir = new GDirections(map, document.getElementById("directions"));
    GEvent.addListener(gdir, "load", onGDirectionsLoad);
    GEvent.addListener(gdir, "error", handleErrors);

    setDirections(document.getElementById("fromAddress").value, document.getElementById("toAddress").value, "en_US");
  }
}

function setDirections(fromAddress, toAddress, locale) {
  gdir.load("from: " + fromAddress + " to: " + toAddress,
            { "locale": locale });
}

这里是URL,我认为是我需要放在我所拥有的地方。

- 我想我可以用一种模式测试它,比如“WALKING”,首先。然后在下载后添加下拉列表。

=====================================

我在以下网址找到了这个网址: https://developers.google.com/maps/documentation/javascript/examples/directions-travel-modes

=========================================

    function calcRoute() {
var selectedMode = document.getElementById('mode').value;
var request = {
  origin: haight,
  destination: oceanBeach,
  // Note that Javascript allows us to access the constant
  // using square brackets and a string value as its
  // "property."
  travelMode: google.maps.TravelMode[selectedMode]
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
  directionsDisplay.setDirections(response);
}
});
}

这是在上面的代码中,我想使用它 travelMode:google.maps.TravelMode [“WALKING”]

1 个答案:

答案 0 :(得分:0)

我明白了。我正在尝试将v3功能/语法添加到v2。卫生署! (拍打额头)