2012-02-29 5 views
-1

다른 공항 위치의지도를 설정 중입니다. 마커가 올바른 위치에 있습니다.Google지도 APIv3 다중 마커/다중 정보 창

정보창을 추가하려고했지만 모든 InfoWindow는 배열의 마지막 마커에서 동일한 내용을 보여줍니다.

각 마커가 고유 한 정보를 갖도록 어떻게 수정해야합니까?

`setMarkers(map, airports); 
} 

    function setMarkers(map, locations) { 

    for (var i = 0; i < locations.length; i++) { 
var airport = locations[i]; 
var myLatLng = new google.maps.LatLng(airport[1], airport[2]); 
var marker = new google.maps.Marker({ 
    position: myLatLng, 
    map: map, 
html: airport[3], 
}); 

var contentString = 
<?php 
$num_rows = (count($locations) - 1); 

for($i = 0; $i < count($locations); $i++){ 

    $query = "SELECT * FROM airports WHERE ident='$locations[$i]'"; 
    $result = mysql_query($query, $link) 
or die('Error querying database.'); 

    while ($row = mysql_fetch_array($result)) { 

if ($i == $num_rows){ 

echo "'<div id=\"content\">'+"; 
echo "'<div id=\"siteNotice\">'+"; 
    echo "'</div>'+"; 
echo "'<b>" . $row['ident'] . "</b></br>'+"; 
echo "'" . $row['latitude_deg'] . ", " . $row['longitude_deg'] . "' +"; 
echo "'</div>'+"; 
    echo "'</div>';"; 
} 
} 
} 
?> 



var infowindow = new google.maps.InfoWindow({ 
content: contentString 
}); 

google.maps.event.addListener(marker, 'click', function() { 
//infowindow.setContent(this.html); 
infowindow.open(map,this); 
}); 
} 
} 

답변

1

각 정보창에 필요한 데이터를 색인 번호로 액세스 할 수있는 정렬로 저장해야합니다.

색인 번호는 사용자가 마커를 클릭 할 때 액세스됩니다. 그런 다음 색인 번호를 사용하여 정보 창 콘텐츠를 즉시 작성하고 정보 창을 엽니 다.

google.maps.event.addListener(marker, 'click', (function(event, index) { 
    return function(){ 
    infowindow.content = markerArray[index].label + "<br>" + markerArray[index].text; 
    infowindow.open(map,this); 
    } 
})(marker,i)); 

코드에서 : http://srsz750b.appspot.com/api3/polylines-multiple.html