我尝试设置这些变量(to、from 和 mode),而不是让用户输入它们。我缺少哪一步?
var from = (40.750484, -111.811177);
var to = (40.775041, -111.718560);
var mode = driving;
//$('#directions-form').submit(function(e) {
//$('#error').hide();
ds.route({
origin: from,
destination: to,
travelMode: mode
}, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
fitBounds = true;
dr.setDirections(result);
}
else {
$('#error').text(status).show();
}
recalcHeight();
});
e.preventDefault();
return false;
});
ds.route(from,to,mode);
最佳答案
尝试...
var from = new google.maps.LatLng(40.750484, -111.811177);
var to = new google.maps.LatLng(40.775041, -111.718560);
var mode = google.maps.TravelMode.DRIVING;
旅行模式文档,其中包含更多模式示例... https://developers.google.com/maps/documentation/javascript/directions#TravelModes
关于javascript - 设置变量,而不是让最终用户从 html 表单输入变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18753823/