Why are you creating another marker at the same spot each time a user clicks
on the marker? That doesn't make sense.
Anyway, if you want to remove the marker on the marker click event is
instead of calling addMarker create a function to deleteMarker which would
iterate through your markersArray and delete the Marker such as:
It would look something like this:
var listener = (google.maps.event.addListener(marker, "click", function () {
for ( var i = 0; i < markersArray.Length; i++ )
{
if ( markersArray[i].id == marker.id )
{
markersArray[i].setMap(null);
markersArray.splice(i, 1);
}
}
}));
I didn't check to make sure you were keeping track of the listeners for all
your markers. If you aren't you need to as you will have a potential memory
leak as the listeners would never be getting deleted, you would use a
similar method of adding and removing the listeners as you do for handling
the markers.
If you have any questions feel free to ask.
On Wed, Jul 6, 2011 at 2:37 PM, Eishita <[email protected]> wrote:
> Ok... So I have updated the things which is available in the following
> link -
>
> http://aiworker2.usask.ca/PasswARGUI1/addLevel.html
>
> Everything is good but the problem is I cannot retrieve the marker's
> id from markersArray. I tried to see id of one of the marker by
> 'alert(markersArray[0].id);' but apparently no alert is visible at
> that time.
>
> Thanks,
> Eishita
>
> On Jul 6, 11:35 am, Eishita <[email protected]> wrote:
> > I'm sorry. Actually I have uploaded the older version of the code.
> > I'll upload the newer one ASAP. Now I'm just doing some coding on it.
> >
> > On Jul 6, 2:36 am, Rossko <[email protected]> wrote:
> >
> > > > You can try out my sample code here -
> >
> > > >http://aiworker2.usask.ca/PasswARGUI1/addLevel.html
> >
> > > <input ... onclick="deleteRow(this)" value="Delete" ..>
> >
> > > What do you think 'this' is in the context of aclickon abutton? It
> > > isn't anymarker.
> >
> > > Use something like the key of your markersArray[] relating to the
> > > particularmarkerwanted. Then, when building yourbuttonwhile
> > > placing themarker, you could write something like
> > > onclick="deleteRow(3)" into yourbutton
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Maps JavaScript API v3" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-maps-js-api-v3?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.