2012-08-08 72 views
4

我想在谷歌地圖api上設置一些路標,但得到以下錯誤。我知道這與設置對象有關,但我似乎無法做到。我也無法找到任何確切的文章。谷歌地圖API錯誤:屬性錯誤<waypoints>:

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

      } 
     }); 

} 

回答

5

路點是不是一個地址或的latLng,它是由(必填)location -member和(可選)stopover -member的對象,所以你的數組應該看起來像這樣:

var waypts = [{location:"Ballybricken"}, 
       {location:"Waterford"}, 
       {location:"Ireland"}, 
       {location:"The Glen"}, 
       {location:"Waterford"}];