I am trying to change the color of a marker/icon with GoogleMaps API V3 based on user input. I can hard code the color or image link I want into the Javascript, but if I try to pass the color or link as a string variable from my Java program then it either does not show up or defaults to a red marker.
I've looked at all the following threads and at the google API:
- Google Maps API 3 - Custom marker color for default (dot) marker
- How do I change icon colour in Google Maps API V3?
- Google Maps API 3 - Custom marker color for default (dot) marker
- https://developers.google.com/maps/documentation/javascript/markers
All of which have either the link to the marker icon they want to use or the color HEX code already hard coded into the javascript.
My attempt, where address1 and color1 are both strings that are passed to the javascript from my Java code. color1's string, for example could be
http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld•|4D8080:
function codeAddress(address1, color1){
var pinColor = color1;
address=address1;
document.geocoder.geocode( {'address': address1}, function(results, status) {
app.callFromJavascript(address1);
if (status == google.maps.GeocoderStatus.OK) {
document.map.setCenter(results[0].geometry.location);
document.map.setZoom(13);
var marker = new google.maps.Marker({
icon: pinColor,
position: results[0].geometry.location,
map: document.map
});
} else {
alert(Geocode was not successful for the following reason: + status);
}
});
}
This results in the map centering on the location and showing the default red marker.
If I change the string passed to color1 to be http://maps.google.com/mapfiles/ms/icons/yellow-dot.png then no marker shows up at all.
What am I missing that I can't get these to generate from passed variables? Is it simply not possible and mandatory that the location markers be hard coded?