Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Maps Api 3 Remove Selected Marker Only
    primarykey
    data
    text
    <p>I've 2 function as below:</p> <pre class="lang-js prettyprint-override"><code>function addMarker() { marker = new google.maps.Marker({ position: Gpoint, map: map, draggable: true, animation: google.maps.Animation.DROP }); map.panTo(Gpoint); google.maps.event.addListener(marker, "rightclick", function (point) { showContextMarker(point.latLng); } ); $('.contextmenu').remove(); }; function delMarker() { marker.setMap(null); $('.contextmenu').remove(); }; </code></pre> <p>So, as may understand I have a Context Menu having "Delete Marker" option on it. I am binding a "rightclick" listener during adding a marker, to show this menu.</p> <p>Everything is working without any problem till this moment.</p> <p>But when I try to click on a marker to delete; it is effecting only the last added marker. When I try again; nothing happens.</p> <p>So my idea is to get the clicked marker's id (or something that may well be useful) and run this deleting function according to this. </p> <p>Briefly; I want to delete the marker that I clicked on, from a map having multiple markers.</p> <p>Do you have any approach to solve this problem ? </p> <p>Thanks in advance!</p> <p><strong>SOLVED!</strong></p> <p>Here is the solution. Thank you Fatih. it was impossible without your guidance:</p> <pre class="lang-js prettyprint-override"><code>var id; var markers = {}; var addMarker = function () { marker = new google.maps.Marker({ position: Gpoint, map: map, draggable: true, animation: google.maps.Animation.DROP }); map.panTo(Gpoint); id = marker.__gm_id markers[id] = marker; google.maps.event.addListener(marker, "rightclick", function (point) { id = this.__gm_id; delMarker(id) }); } var delMarker = function (id) { marker = markers[id]; marker.setMap(null); } </code></pre> <p>Calling delete function by: <code>delMarker(id)</code> Ps: "Right clicking is enough on this case"</p> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload