Öffnen Sie InfoWindow für jedes Polygon Google Maps V3

Hoffe, jemand kann mir bei diesem Problem helfen. Ich versuche, beim Klicken ein Informationsfenster für jedes von meinen Benutzern erstellte Polygon zu öffnen. Ich habe den gleichen Code für einen Marker verwendet und funktioniert gut, aber ich konnte ihn nicht für jedes Polygon verwenden.

Überlegen Sie, wie Sie dieses Problem lösen können?

Vielen Dank.

var contentString = '<div id="content">'+
    '<div id="siteNotice">'+
    '</div>'+
    '<h2>Test</h2>'+
    '</div>';

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

// Bereiche anzeigen

<?php foreach ($field->result() as $f):?>

// Create an array with the coordanates of each area

var field<?=$f->id?>Coords = [
    <?php $latlng=$this->resources_data->field_latlng($f->id);?>
    <?php foreach ($latlng->result() as $point):?>
    new google.maps.LatLng(<?=$point->lat?>, <?=$point->lng?>),
    <?php endforeach;?>
];

// Create a polygon with the points of the area

var area<?=$f->id?>=new google.maps.Polygon({
    paths: area<?=$f->id?>Coords,
    strokeColor: '#FF0000',
    strokeOpacity: 0.8,
    strokeWeight: 2,
    fillColor: '#FF0000',
    fillOpacity: 0.35
});

// Add the area to the map.

area<?=$f->id?>.setMap(map);

google.maps.event.addListener(area<?=$f->id?>,'click',function(){
    infowindow.open(map,area<?=$f->id?>)
});

<?php endforeach;?>

Antworten auf die Frage(2)

Ihre Antwort auf die Frage