4

Google マップ API でいくつかのウェイポイントを設定しようとしていますが、次のエラーが発生します。オブジェクトの設定と関係があることは知っていますが、正しく理解できないようです。また、それに関する正確な記事も見つかりません。

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

私のコード

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);

            }
        });

}
4

1 に答える 1

5

ウェイポイントはアドレスやlocationlatLngではなく、(必須の)メンバーと(オプションの)メンバーで構成されるオブジェクトであるstopoverため、配列は次のようになります。

var waypts = [{location:"Ballybricken"},
              {location:"Waterford"},
              {location:"Ireland"},
              {location:"The Glen"},
              {location:"Waterford"}];
于 2012-08-10T21:29:41.147 に答える