My favorites | Sign in
Project Home Issues
New issue   Search
for
  Advanced search   Search tips   Subscriptions
Issue 4087: Bug: Deleted markers reappear (v. 3.8)
3 people starred this issue and may be notified of changes. Back to list
Status:  Fixed
Owner:  [email protected]
Closed:  May 2012


Sign in to add a comment
 
Reported by [email protected], Apr 19, 2012
I found a bug in version 3.8 (the previous versions works correctly).

In some cases, I delete a marker (with a custom image) with setMap(null) and the marker disappear. If I zoom the map the marker reappear.
If, instead of remove it, I change position, zooming the map I see 2 marker: one in the old position and one in the new position.

Apr 19, 2012
Project Member #1 [email protected]
Please provide a demo that illustrates the bug.
Status: NeedsMoreInfo
Owner: [email protected]
Apr 20, 2012
#2 [email protected]
Below I've attached the sample code (attachment is not working!).
If you click add and then remove, when you zoom the wrong marker is showed.
My case is more complex, but I think the source of problem is the same.


<html>
<head>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language=it&region=IT"></script>

<script type="text/javascript">

  var map, markers=[];

  function init() {
    map=new google.maps.Map(document.getElementById('map_canvas'),{
      zoom: 9,
      center: new google.maps.LatLng(43,12),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    new google.maps.Marker({
      position: new google.maps.LatLng(43,12),
      title: '1',
      map:   map
    });
  }

  function add() {
    var image=new google.maps.MarkerImage(
      'https://developers.google.com/maps/documentation/javascript/examples/images/beachflag.png',
      new google.maps.Size(20,32),
      new google.maps.Point(0,0),
      new google.maps.Point(0,32)
    );

    var marker=new google.maps.Marker({
      title:    '',
      icon:     image,
      map:      map,
      position: new google.maps.LatLng(43-(markers.length/10),12-(markers.length/10)),
      zIndex:   2
    });
    markers.push(marker);
  }

  function remove() {
    if (!markers.length) return;
    var marker=markers.pop();
    marker.setMap(null);
    marker=undefined;
  }

</script>

</head>
<body onload="init()">
  <div id="map_canvas" style="height:400; width:400"></div>
  <button onclick="add()">Add</button>
  <button onclick="remove()">Remove</button>
</body>
</html>

Apr 22, 2012
Project Member #3 [email protected]
(No comment was entered for this change.)
Status: Confirmed
Labels: Internal-6377905
May 16, 2012
#4 [email protected]
Hello there,

Just for reference I've been stuck on this exact same problem this morning. I've found a work around now which works for me, which actually in the long run might prove to be better practise. All I've done is instead of removing the marker and creating a new one, I've simply updated the old marker object with the new information, position and image etc, then removed and re-added it to the map.

I'm not sure if this will help for your situation but until google fix the bug maybe it will help anyone who glances on this thread when having the issue like we have.

Good luck,
Laurence.
May 16, 2012
Project Member #5 [email protected]
This should have been fixed already. If you have a problem with your markers, please post a link to your demo.
Status: Fixed
Jun 18, 2016
#6 [email protected]
This is still an issue. Not only does it affect markers, but polylines, and info windows as well. 
Jan 17, 2017
#7 [email protected]
I have the same issue. Any update about this? 

BR,
Jan 17, 2017
#8 [email protected]
Solved like this:


for (var i = 0; i < markers.length; i++){
markers[i].setMap(null);
}
handler.removeMarkers(markers);
markers = [];

Best regards,
Sign in to add a comment

Powered by Google Project Hosting