【问题标题】:Google maps walking directions with javascript谷歌使用 javascript 绘制步行路线图
【发布时间】:2012-11-03 05:53:54
【问题描述】:

我正在尝试提供建筑物之间的校园步行路线。当我使用以下代码时,起点和终点坐标被放置在最近的命名道路上,而不是指定的特定路径上。

    var request = {
    origin: "34.23974770397957,-118.53099968624116",
        destination: "34.240064785369974,-118.52827992630006",
        travelMode: google.maps.DirectionsTravelMode.WALKING
    };
    directionsService = new google.maps.DirectionsService();
    directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
      }
    });

您可以在http://www.csun.edu/~kjm39451/maps/mapsError/main.html 处通过选择两个字段中任何内容的下拉菜单来查看问题。

但我希望结果看起来像这样https://maps.google.com/maps?saddr=34.23974770397957,-118.53099968624116&daddr=34.240064785369974,-118.52827992630006&hl=en&ll=34.239825,-118.530614&spn=0.003721,0.004823&sll=34.23962,-118.52964&sspn=0.003721,0.004823&geocode=FQR1CgIdSFzv-A%3BFUF2CgId6Gbv-A&dirflg=w&mra=ls&t=m&z=18

如何使用 google maps api 像 google maps 一样提供方向?

【问题讨论】:

    标签: javascript json google-maps


    【解决方案1】:

    DirectionsRequest 的目标和源属性可以采用字符串或 LatLng 类。如果您提供LatLng,它似乎可以正常工作。

    var request = {
      origin: new google.maps.LatLng(34.23974770397957, -118.53099968624116),
      destination: new google.maps.LatLng(34.240064785369974, -118.52827992630006),
      travelMode: google.maps.DirectionsTravelMode.WALKING
    };
    

    您可以参考地图 API 文档: https://developers.google.com/maps/documentation/javascript/3.exp/reference#DirectionsRequest

    https://developers.google.com/maps/documentation/javascript/reference#LatLng

    【讨论】:

      猜你喜欢
      • 2014-03-19
      • 2016-05-14
      • 1970-01-01
      • 2013-10-25
      • 1970-01-01
      • 2013-06-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多