简体   繁体   中英

Delete a single marker with a button click in Google Maps API

I have created something like following -

  1. In a Google map I'll place markers by clicking and there will be a table row created dynamically with each click and will show the lat, long in that table row.

  2. i have put a delete button with each of the table row which deletes the corresponding row.

What I want -

I want when the row is deleted, the corresponding marker should also be deleted from the map. I have no clue how can I associate that specific marker with that delete button.

Any sort of help will be appreciated. A rough look of my page is available here-

My Sample Code

Look here: http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/c0e80cdbde13dd36/0bb97b3de988b4f7?lnk=gst&q=remove+markers&pli=1

I guess you need to add markers to the array when creating them. Then you can set and index that relate to that marker to be the value of hidden field next to the Delete button. Or you can set the marker's index as href for anchor tag and use anchor tag instead of a button to call the removal function for that particular marker.

You can also check out discussion here: http://www.svennerberg.com/2009/07/google-maps-api-3-markers/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM