Tuesday, February 10, 2009

Issue on GEvent.trigger(gmarkers[i], "click"); on google map

Issue on GEvent.trigger(gmarkers[i], "click"); on google map

Hi

i have function like this

function myPrevClick(it)
{
        it--;       
        GEvent.trigger(gmarkers[it], "click");

}

when I give any values other than 0 it works for me. COuld you please
help me to find out the reason, why this happening :(

thanks
jj
http://phpqa.blogspot.com


***********************************
Andrew wrote
***********************************

Isn't this a basic Javascript problem? You pass zero as "it"; "it" is
decremented and so you attempt to click gmarkers[-1]. I don't expect
you have a marker with that index.

Andrew

***********************************

***********************************

thanks for your reply

sorry I replaced the 'it' to zero on this line GEvent.trigger(gmarkers
[it], "click");

am not getting the 0the index

ie

GEvent.trigger(gmarkers[0], "click");

Thanks
jj
http://phpqa.blogspot.com

***********************************
Andrew wrote
***********************************

Well presumably you don't have a marker at that index either. You
haven't given a link to your map, so it's not possible to see exactly
what's going on.

Andrew

***********************************
Andrew wrote
***********************************

I can't make that map go wrong. I can enter
  javascript:GEvent.trigger(gmarkers[0],'click')
into the browser address bar and it works. What steps are necessary to
make it fail?

Andrew

***********************************

***********************************

Could you  please try

javascript:GEvent.trigger(gmarkers[0],'click') ;
javascript:GEvent.trigger(gmarkers[10],'click') ;

same infobox window opening while we use the above commands :(

have a look on it

thanks
jj
http://phpqa.blogspot.com

***********************************
Marcelo wrote
***********************************

It's because you are overwriting the first value in the gmarkers
array.

First you do
gmarkers.push(marker);

and later,
gmarkers[i] = marker;

where i is a global variable set to 0.

So, every time you call createMarker() the value of gmarkers[0] gets
overwritten.

Marcelo