使用Google地图路线修改或停用信息窗口

时间:2016-03-04 16:47:24

标签: javascript jquery google-maps google-maps-api-3

我需要使用Google地图路线编辑或至少禁用信息窗。enter image description here

这是我的代码

function calcRoute() {
    marker.setMap(null);

    var infowindow1 = '<div class="venue_map_infowindow"><a class="location" href="javascript:void(0);"><h3>My Position</h3></a></div>';
    var infowindow2 = '<div class="venue_map_infowindow"><a class="location" href="javascript:void(0);"><h3>Your Position</h3></a></div>';;

    var request = {
        origin: myLatLng,
        destination: venue_coords,
        travelMode: google.maps.TravelMode.DRIVING,
    };
    directionsService.route(request, function(result, status) {
        if (status == google.maps.DirectionsStatus.OK) {
            directionsDisplay.setDirections(result);
        }
        else {
            window.alert('Directions request failed due to ' + status);
        }
    });
    directionsDisplay.setMap(map);
}

提前感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

您可以像这样分配infoWindow:

var directionsDisplay = new google.maps.DirectionsRenderer({
  infoWindow: myInfoWindow,
  map: map
});

您可以创建editableInfoWindow。 看这里。 http://googlemaps.googlermania.com/google_maps_api_v3/en/editable_infowindow.html

另一个答案是,只需禁用infoWindow:

var directionsDisplay = new google.maps.DirectionsRenderer({
  suppressInfoWindows: true,
  map: map
});

你可以解析directionResult,然后自己添加infoWindows。 阅读本页: http://googlemaps.googlermania.com/google_maps_api_v3/en/map_example_direction_customicon.html

答案 1 :(得分:0)

这对我有用:

    directionsService.route(request, function(result, status) {
        if (status == google.maps.DirectionsStatus.OK) {
            result.routes[0].legs[0].start_address = window0;
            result.routes[0].legs[0].end_address = window1;
            directionsDisplay.setDirections(result);
        }
        else {
            window.alert('Directions request failed due to ' + status);
        }
    });
相关问题