【问题标题】:how to get multiple paths between locations on a google map using fragment如何使用片段在谷歌地图上的位置之间获取多条路径
【发布时间】:2018-07-07 10:22:25
【问题描述】:

这是我用来绘制单个路径的代码。请向我提供有用的详细信息,以便我找到不同的路径。

calculateAndDisplayRoute() {

    var directionsService = new google.maps.DirectionsService;          
    var directionsDisplay = new google.maps.DirectionsRenderer;        
    var map = new google.maps.Map(document.getElementById('map'), {
                zoom: 7,
                center: {lat: 41.85, lng: -87.65}
              });

    directionsDisplay.setMap(map);

    directionsService.route({

        origin: this.start,      
        destination: this.end,     
        travelMode: 'DRIVING'     
    }, function(response, status) {

            if (status === 'OK') {
                directionsDisplay.setDirections(response);
            } else {
                 window.alert('Directions request failed due to ' + status);
            }
    });

}

ionViewDidLoad() {
    this.calculateAndDisplayRoute();   
}

【问题讨论】:

    标签: angular google-maps google-maps-api-3 ionic3


    【解决方案1】:

    您可以使用路线请求对象的provideRouteAlternatives 属性:

    https://developers.google.com/maps/documentation/javascript/reference/3/directions#DirectionsRequest.provideRouteAlternatives

    如果您将此属性设置为 true,则服务将在您的点之间返回最多 3 条替代路线。你的代码应该是

    directionsService.route({
        origin: this.start,      
        destination: this.end,     
        provideRouteAlternatives: true,
        travelMode: 'DRIVING'     
    }, function(response, status) {
            if (status === 'OK') {
                directionsDisplay.setDirections(response);
            } else {
                 window.alert('Directions request failed due to ' + status);
            }
    });
    

    我希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多