I’m using coldfusion to populate a google map – and I want different colored markers for things
Using Google Maps API v3
This code works but they are all 1 marker color – green is always showing – I cannot get the different colors showing.
Thoughts? Thanx for any input
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<script type="text/javascript">
var locations =
[
<cfloop query=due>
<cfoutput>
<cfquery name="info" datasource="data">
SELECT * FROM data
WHERE id = #due.id#
</cfquery>
<cfif info.gpslat is not "">["#info.id#", #info.gpslat#, #info.gpslong#, #info.id#],</cfif>
</cfoutput>
</cfloop>
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 14,
center: new google.maps.LatLng(51.19, -114.48),
mapTypeId: google.maps.MapTypeId.HYBRID
});
var infowindow = new google.maps.InfoWindow();
<cfloop query=due>
<cfquery name="info" datasource="data">
SELECT * FROM data
WHERE id = #due.id#
</cfquery>
var marker, i;
<cfif info.gpslat is not "">
<cfif due.data is 'yes'>
var image = 'red.png';
</cfif>
<cfif due.data is 'no'>
var image = 'green.png';
</cfif>
</cfif>
</cfloop>
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map,
icon: image
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
</script>
You’re mixing javascript and ColdFusion code and so the marker image taken is the last one available in your loop. Something that may work would be
Code is not optimized also… but that’s another thing 🙂