I have made a custom Google map with two sets of markers. I'm trying to write a function to clear the markers but can't get it to work.
The function:
function clearMarkers() {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(null);
}
markers = [];
};
This works when the markers are in the lat, long format like below:
var locs1 = [
{lat: 51.2, lng: 0},
{lat: 52, lng: 0.3}
]
But when I use an array to define the markers (as below) it no longer works:
var locs1 = [
['Name', 51.2, 0, 'Info'],
['Name', 52, 0.3, 'Info']
];
How can I make the clearMarkers function work properly?
Full code can be found in this Fiddle to help understand context.