Skip to content

Instantly share code, notes, and snippets.

@wf9a5m75
Last active August 29, 2015 14:00
Show Gist options
  • Save wf9a5m75/11010385 to your computer and use it in GitHub Desktop.
Save wf9a5m75/11010385 to your computer and use it in GitHub Desktop.
Remove all markers when the map dialog is closed. (phonegap-googlemaps-plugin)
<!DOCTYPE html>
<html>
<head>
<script src="cordova.js"></script>
<script src="remove_marker.js"></script>
</head>
<body>
<button id="button1" >Open a map, then add markers</button>
<br>
<br>
<button id="button2" >Open a map</button>
</body>
</html>
function onMapReady(map) {
/**
* Show the map dialog, then add markers.
*/
var button1 = document.getElementById("button1");
button1.addEventListener("click", function() {
map.showDialog();
/**
* Add markers
*/
const GOOGLE = new plugin.google.maps.LatLng(37.422858, -122.085065);
const GOOGLE_TOKYO = new plugin.google.maps.LatLng(35.660556,139.729167);
const GOOGLE_SYDNEY = new plugin.google.maps.LatLng(-33.867487,151.20699);
const GOOGLE_NY = new plugin.google.maps.LatLng(40.740658,-74.002089);
var GOOGLES = [GOOGLE, GOOGLE_TOKYO, GOOGLE_SYDNEY, GOOGLE_NY];
GOOGLES.forEach(function(latLng) {
map.addMarker({
'position': latLng
}, function(marker) {
// Bind the MARKER_REMOVE event
map.addEventListenerOnce("MARKER_REMOVE", function() {
marker.remove();
});
});
});
map.moveCamera({
'target': GOOGLES
});
});
/**
* When the map dialog is closed,
* then invokes the MARKER_REMOVE event for all markers.
*/
map.addEventListener(plugin.google.maps.event.MAP_CLOSE, function() {
map.trigger("MARKER_REMOVE");
});
/**
* Show the map dialog
*/
var button2 = document.getElementById("button2");
button2.addEventListener("click", function() {
map.showDialog();
}, false);
}
@wf9a5m75
Copy link
Author

img

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment