2012-08-08 75 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"}];