Last active
July 19, 2018 12:26
-
-
Save getsudocode/d05288482c456c95565bb33ef243aa7e to your computer and use it in GitHub Desktop.
change JavaScript Google Map marker color
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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