谷歌地图api错误:属性<waypoints>出错:

Kei*_*wer 4 javascript google-maps-api-3

我试图在谷歌地图api上设置一些路标,但得到以下错误.我知道它与设置一个对象有关,但我似乎无法正确对待它.我也找不到任何确切的文章.

Error: Error in property <waypoints>: (Invalid value: Ballybricken, Waterford, Ireland,The Glen, Waterford (Error in element at position 0: (Unknown property <0>)))
Run Code Online (Sandbox Code Playgroud)

我的代码

var waypts = ["Ballybricken, Waterford, Ireland", "The Glen, Waterford"];
drawPolyline('Waterford Regional Hospital', 'Hillview, Waterford, Ireland', waypts);


function drawPolyline(source,destination,waypoints){
        // show route between the points
        directionsService = new google.maps.DirectionsService();
        directionsDisplay = new google.maps.DirectionsRenderer(
        {
            suppressMarkers: true,
            suppressInfoWindows: true,
            polylineOptions: { strokeColor: '#000000', strokeOpacity: 0.5 } 
        });
        directionsDisplay.setMap(map);
        var request = {
            origin:source, 
            destination:destination,
            waypoints:waypoints,
            travelMode: google.maps.DirectionsTravelMode.DRIVING
        };
        directionsService.route(request, function(response, status) 
        {
            if (status == google.maps.DirectionsStatus.OK) 
            {
                directionsDisplay.setDirections(response);

            }
        });

}
Run Code Online (Sandbox Code Playgroud)

Dr.*_*lle 5

航点不是地址或latLng,它是一个由(必需的)location成员和(可选)stopover成员组成的对象,因此您的数组应如下所示:

var waypts = [{location:"Ballybricken"},
              {location:"Waterford"},
              {location:"Ireland"},
              {location:"The Glen"},
              {location:"Waterford"}];
Run Code Online (Sandbox Code Playgroud)