On Jan 16, 6:53 pm, Iam Anonymous <[email protected]> wrote:
> I have a marker array that needs to be re-set after I load a new
> map.  I also want to be able to double-click markers to erase them.
> Simplified code
> looks like:
>
> for(i=0;i<allPins.length;i++){if(allPins[i]!=null){
>     allPins[i].setMap(griddedMap);
>     google.maps.event.addListener(allPins[i], 'dblclick',
> function(obj) {
>         allPins[i].setMap(null);
>         allPins[i] = null;
>     });
>
> }};
>
> When I double-click a marker, it is kind of random what happens.
>  Sometimes the map zooms, indicating no listener.  Sometimes more
> than one marker will disappear.  Sometimes it works.  Very strange.
>
> I think the problem is the two references to allPins[i] inside the
> listener
> function are getting evaluated at run time with some random value
> of i.  
> What I really am trying to refer to is the marker that is being
> clicked, passed to the listener from the array: allPins[i].  

Try using function closure.

That looks a lot like pitfall #3.
http://groups.google.com/group/google-maps-js-api-v3/search?group=google-maps-js-api-v3&q=pitfall+%233&qt_g=Search+this+group


> Said
> another way, I need something lilke:
>
> markerbeingclicked.setMap(null);
> markerbeingclicked = null;
>
> but I don't think that's what I am getting when I use allPins[i].
>  Any suggestions?

Post a link to your map that exhibits the problem.
http://groups.google.com/group/google-maps-js-api-v3/t/2b3f101fd509919e

  -- Larry

-- 
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.

Reply via email to