0

我正在使用谷歌地图 api V3,有些事情出错了路线没有显示。这是代码

function addRoute(source,destination,color){
        deleteOverlays();
        var arr = [];
        var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
        var queryString = "?source=" + source+"&destination="+destination;
        request.open("GET","url to get the stops"+ queryString, true);
        request.send(null);
        request.onreadystatechange = function() {
            if (request.readyState == 4) {
                if (request.status == 200) {
                    route = eval(request.responseText);
                    for(var i = 0; i < route.length; i++){
                        //alert("route::"+route[i].stopname);
                        var marker = addMarker(new google.maps.LatLng(route[i].lattitude,route[i].langitude),route[i].stopname);
                        markersArray.push(marker);
                        arr.push({ location: new google.maps.LatLng(route[i].lattitude,route[i].langitude), stopover: true });
                        map.setCenter(new google.maps.LatLng(route[i].lattitude,route[i].langitude));

                    }
                    drawPolyline(source,destination,arr,color);
                    showOverlays();
                }
            }
        };
}

ajax 响应是这种格式

[{"stopname":"Bookstore,Hamilton,NY","lattitude":42.8040014451186,"langitude":-75.548035569867},{"stopname":"Townhouse,Hamilton,NY","lattitude":42.8094640653946,"langitude":-75.5441731888855},{"stopname":"Cutten Hall,Hamilton,NY","lattitude":42.8162955973712,"langitude":-75.5402678925598},{"stopname":"Whitnall Field,Hamilton,NY","lattitude":42.8177908781254,"langitude":-75.5412549454773},{"stopname":"Person Hall,Hamilton,NY","lattitude":42.8179325344271,"langitude":-75.5369204957092},{"stopname":"Frank Dining Hall,Hamilton,NY","lattitude":42.8159650567458,"langitude":-75.5374569375122},{"stopname":"Person Hall,Hamilton,NY","lattitude":42.8178066177305,"langitude":-75.536877580365},{"stopname":"Whitnall Field,Hamilton,NY","lattitude":42.817633481854,"langitude":-75.5412334878052},{"stopname":"University Ct./Burch,Hamilton,NY","lattitude":42.8183102829785,"langitude":-75.5432934243286},{"stopname":"Parker Apartments,Hamilton,NY","lattitude":42.8182945435016,"langitude":-75.5456108529175},{"stopname":"Newell Apartments ,Hamilton,NY","lattitude":42.8179167948541,"langitude":-75.5466837365235}]




    function drawPolyline(source,destination,waypoints,color){
         var polylineOptionsActual = { strokeColor: color };
         var directionsDisplay = new google.maps.DirectionsRenderer({
                suppressMarkers: true,
                suppressInfoWindows: true,
                polylineOptions: polylineOptionsActual
           }); 
         var directionsService = new google.maps.DirectionsService();
         directionsDisplay.setMap(map);
         //var mode = google.maps.DirectionsTravelMode.DRIVING;
         var request = {
                    origin: source,
                    destination: destination,
                    travelMode: google.maps.TravelMode.DRIVING,
                    waypoints:waypoints
                };
                directionsService.route(request, function(response, status) {
                  if (status == google.maps.DirectionsStatus.OK) {
                    directionsDisplay.setDirections(response);
                    directionsArray.push(directionsDisplay);
                  }
                });
    }

every value is going fine.

但路线没有显示,谷歌地图api V3有什么改变吗?

4

1 回答 1

0

假设您没有营业执照:

有最大值的限制。8 个航路点,但您目前有 11 个。

检查 的status回调directionsService.route(),您应该收到“MAX_WAYPOINTS_EXCEEDED ”-警告

于 2012-05-05T09:54:34.483 回答