62,046
社区成员
发帖
与我相关
我的任务
分享
function calcRoute() {
//出发地
var start = document.getElementById("start").value;
//目的地
var end = document.getElementById("end").value;
//出行方式
var selectedMode = document.getElementById("TravelMode").value;
var image = new google.maps.MarkerImage('IMG/icon.png',
new google.maps.Size(19, 30));
var request = {
origin: start,
destination: end,
travelMode: google.maps.DirectionsTravelMode[selectedMode]
};
directionsService.route(request, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
var location = new google.maps.LatLng(28.681984, 115.906947);
var marker = new google.maps.Marker({
position: location,
map: map,
icon: image
});
marker.setTitle("1");
attachSecretMessage(marker, 0);
}
<strong>出发地: </strong>
<input id="start" type="text" />
<strong>目的地: </strong>
<input id="end" type="text" style="width:200px;" />
<strong>出行方式: </strong>
<select id="TravelMode">
<option value="WALKING">步行</option>
<option value="DRIVING">乘车</option>
</select>
<input id="searchButton" type="button" value="搜索路线" onclick="calcRoute();" />