javascript - 设置变量,而不是让最终用户从 html 表单输入变量

标签 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);

最佳答案

尝试...

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/

相关文章:

javascript - 无法在Leaflet map 上绘制从geoJson获取的点

javascript - Typescript - 将接口(interface)文字传递给函数参数

google-maps - 谷歌自动完成查询的限制?

javascript - 单击按钮时,如何将数字存储在 html 表单输入中作为 javascript 变量?

iphone - Objective-c:在数组内分配变量而不是字符串

ruby - 在 Chef 资源之间传递变量

javascript - 如何注释自定义请求 header 的类型?

javascript - this.setState 不会重新渲染 View ReactJS 和 Ruby on Rails

html - 谷歌地图未显示在 div 中

android - 如何手动将 Google API 库添加到 Eclipse 中的项目?