Last active
December 21, 2015 20:28
-
-
Save daviosa/6361013 to your computer and use it in GitHub Desktop.
Javascript code to handle markers on GoogleMaps API. Keywords: GoogleMaps API, Marker, Overlay, Javascript, GIS
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
var markersArray = []; | |
function addMarkerOnClick(mapClient){ | |
google.maps.event.addListener(mapClient, 'click', function(event) { | |
addMarker(event.latLng); | |
}); | |
} | |
function addMarker(mapClient, location) { | |
marker = new google.maps.Marker({ | |
position: location, | |
map: mapClient | |
}); | |
markersArray.push(marker); | |
} | |
//Removes the overlays from the map, but keeps them in the array | |
function clearOverlays() { | |
if (markersArray) { | |
for (i in markersArray) { | |
markersArray[i].setMap(null); | |
} | |
} | |
} | |
//Shows any overlays currently in the array | |
function showOverlays(mapClient) { | |
if (markersArray) { | |
for (i in markersArray) { | |
markersArray[i].setMap(mapClient); | |
} | |
} | |
} | |
//Deletes all markers in the array by removing references to them | |
function deleteOverlays() { | |
if (markersArray) { | |
for (i in markersArray) { | |
markersArray[i].setMap(null); | |
} | |
markersArray.length = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment