设置变量而不是让最终用户从html表单输入它们

时间:2013-09-12 01:17:50

标签: javascript google-maps variables

我试图设置这些变量(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);

1 个答案:

答案 0 :(得分:1)

尝试......

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