Hi Sergiy,
I did manage to get the last marker to be removed. This was done by changing var marker to a global variable. When clicking a button, call marker.setMap(null);. This however removes only the last marker placed.
My code and the way the Google example work are different. I'm walking through an array, placing the marker for each pass. I see that the Google code sets the marker on the map, but my code seems to do this as soon as you create the marker. If I try setting the marker as Google does, I get markers which update without coordinates and are placed in the middle of the world map.
It took two weeks to get the markers to even appear. I don't want to rewrite everything just in order to delete a marker.
Can someone please throw me a bone here????
[quote:]
list_location = [];
var list_location = localStorage.getItem('farmProducts_storage');
obj = [];
var obj = JSON.parse(list_location);
var coordsArray = obj;
marker = [];
markers = [];
var image = 'http://chart.apis.google.com/chart?ch...';
var map = [];
var map = new Appery("Gmap").options.mapElement.gmap('get', 'map');
var CreateMarker = function(coordsArray, i){
Code: Select all
marker = new google.maps.Marker({
position: new google.maps.LatLng( coordsArray[i].lat, coordsArray[i].lng ),
title: coordsArray[i].business_name,
map: Appery("Gmap").gmap,
});
// Adds a marker to the map and push to the array.
markers.push(marker);
alert (markers);
Code: Select all
var infowindow = new google.maps.InfoWindow({content: ('[b]' + coordsArray[i].business_name + '[/b]
' + coordsArray.hours_season + '
' + coordsArray.combinedAddress )});
Code: Select all
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(Appery("Gmap").gmap,marker);
});
};
for (var i = 0, j = coordsArray.length; i < j; i++)
CreateMarker(coordsArray, i);
google.maps.event.addListener(map, 'bounds_changed', function() {
// Adds a marker to the map and push to the array.
});
[/quote]