2013-02-25 157 views
0

(对不起,我的英语) 我想要做集群,但我有错误
遗漏的类型错误:对象[对象数组]有没有方法“为getPosition” COORDS我从数据库中取谷歌地图集群

 function initialize() { 
     var latlng = new google.maps.LatLng(56.323678, 44.0); 
     var myOptions = { 
      zoom: 7, 
      center: latlng, 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
     }; 
    var map = new google.maps.Map(document.getElementById("map_canvas"), 
     myOptions); 
     setMarkers(map, markers); 
    } 

var markers = [ <? for ($i=0; $i<count($cords); $i++) 
{if((float)$cords["$i"]["location_lat"]<>0 AND (float)$cords["$i"]["location_lng"]<>0 ){echo "[".(float)$cords["$i"]["location_lat"].", 
".(float)$cords["$i"]["location_lng"]." , 
'".$cords["$i"]["image"]."', 
'".$cords["$i"]["name"]."']"; 
if ($i+1<count($cords))echo ",\n\r";}}?> ]; 
var infowindow = new google.maps.InfoWindow({ 
}); 
function setMarkers(map, locations) { 
var markerCluster = new MarkerClusterer(map, locations); 
var latlngbounds = new google.maps.LatLngBounds(); 
     for (var i = 0; i < markers.length; i++) { 
      var myLatLng = new google.maps.LatLng(locations[i][0], locations[i][1]); 

      latlngbounds.extend(myLatLng); 
      var marker = new google.maps.Marker({ 
       position: myLatLng, 
       map: map, 
       title: locations[i][3] 
      }); 
google.maps.event.addListener(marker, 'click', (function(marker, i) { 
     return function() { 
      infowindow.setContent("<img src='image/"+ locations[i][2] +"' height='150' width='300'> <br> <b>"+ locations[i][3] +"</b> "); 
      infowindow.open(map, this); 
     } 
     })(marker, i)); 
      } 
    map.setCenter(latlngbounds.getCenter(), map.fitBounds(latlngbounds));  
    }; 

回答

0

我觉得你还没有说明你想要做的“getPosition”, 这个数组的索引,你的代码太乱了.. :)