# Remove Gmap marker using YM4R

**URL:** <https://www.ruby-forum.com/t/remove-gmap-marker-using-ym4r/134950>\
**Category:** Rails\
**Created:** [April 16, 2008, 3:24pm UTC](https://www.ruby-forum.com/t/remove-gmap-marker-using-ym4r/134950 "2008-04-16T15:24:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kamhei82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a88e4f/32.png) [@kamhei82](https://www.ruby-forum.com/u/kamhei82)\
**Post date:** [April 16, 2008, 3:24pm UTC](https://www.ruby-forum.com/t/remove-gmap-marker-using-ym4r/134950/1 "2008-04-16T15:24:30Z")

</div>

Hello,  
I’m using [http://ym4r.rubyforge.org](http://ym4r.rubyforge.org) and I have a problem with removing  
existing marker. I tried this (.rjs file):

```auto
if @params[:gobject] == "on"
  @gobject_results.each {|marker| page << @map.addOverlay(marker)}
else
  @gobject_results.each {|marker| page << @map.removeOverlay(marker)}
end
```

but it doesn’t work (I mean it only adds marks). I read on google maps  
API forums, that I need to have array of marks which was added, to  
remove them later.  
Please help me write this .js code in .rjs file:

```auto
var MarkersArray = []; // global

var marker = new GMarker(PointsArray[Counter]);
// Adding:
map.addOverlay(marker);
MarkersArray[Counter] = marker;

// So I can remove a marker with:
map.removeOverlay(MarkersArray[Counter]);
```

Thank you in advance,  
Stan
