0
我有我的自定義地圖工作的方向。不過,我希望添加我在Google開發者網站上找到的下拉菜單,該下拉菜單允許選擇「自行車」,「駕駛」,「過境」,「步行」等選項。我的Google地圖代碼中的哪個地方可以將Travel模式添加到Directions?
這裏是我的代碼,它的功能我不知道他們在哪裏:
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 [ 「行走」]