Skip to content

Instantly share code, notes, and snippets.

@getsudocode
Last active July 19, 2018 12:26
Show Gist options
  • Save getsudocode/d05288482c456c95565bb33ef243aa7e to your computer and use it in GitHub Desktop.
Save getsudocode/d05288482c456c95565bb33ef243aa7e to your computer and use it in GitHub Desktop.
change JavaScript Google Map marker color
let map;
// global array to store the marker object
let markersArray = [];
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 8
});
addMarker({lat: -34.297, lng: 150.544}, "yellow");
addMarker({lat: -34.397, lng: 150.644}, "green");
addMarker({lat: -34.597, lng: 150.844}, "blue");
}
function addMarker(latLng, color) {
let url = "http://maps.google.com/mapfiles/ms/icons/";
url += color + "-dot.png";
let marker = new google.maps.Marker({
map: map,
position: latLng,
icon: {
url: url
}
});
//store the marker object drawn in global array
markersArray.push(marker);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment