Ask PHP to set javascript code.
Here is a small handy javascript function that I wrote to add a marker with the appropriate window.
function add_marker(opts, place) {
var marker = new google.maps.Marker(opts);
marker.place_id = place.id;
markers[place.id] = marker;
var infowindow = new google.maps.InfoWindow({
content: place.details
});
infowindows[place.id] = infowindow;
google.maps.event.addListener(marker, 'click', function() {
infowindows[marker.place_id].open(map,marker);
});
}
So, declaring that in some javascripty place you will have some PHP, which will probably resemble (and if your map is global, called "map"):
<script type="text/javascript">
<?php
$count = 0;
foreach ($rowset as $row): ?>
add_marker({
position: new google.maps.LatLng(<?php echo $row->lat ?>, <?php echo $row->lng ?>),
title:<?php echo $row->title ?>,
map:map
}, { id:'<?php echo $count ?>', details:'<?php echo $row->details ?>' });
<?php
$count++;
endforeach; ?>
</script>
I have not tested anything and do not know what the data looks like, but this method should work for what you want. I'm not 100% sure what you mean by creating custom markers, because it looks like you're already doing this, just not through PHP.
source
share