On May 1, 12:17 am, dms <diegui
...@gmail.com> wrote:
> in other words... im sending addressPoint (GLatLang) to the add_marker
> function instead of sending one parameter to lat and other to lng.
That's irrelevant. GMarker, which is the ultimate destination of your
"addressPoint", takes a GLatLng as the first parameter.
> the script is working but for every result the addressPoint is the
> same. is not saving the data for each "li" maybe is a javascript
> problem, not api problem but... maybe one of you can give me a hand
> with these.
It's a scope issue. Every li element gets
new_li.onclick = function(){add_marker(addressPoint)}
and addressPoint is a global variable. That means that whenever an li
is clicked, it uses whatever value of addressPoint that variable
happens to contain at the time. You need a helper function to gain
function closure on new_li and its addressPoint so that each li keeps
its own value. Mike deals with a similar issue in
http://econym.googlepages.com/basic1.htm
-- you've fallen into Pitfall Number Three.
Andrew
Something like this...
for(i=0;i<=data.Placemark.length-1;i++){
addressPoint = new GLatLng(...,...);
document.getElementsById('ul')
[0].appendChild(make_li(addressPoint));
}
function make_li(pt) {
var new_li = document.createElement('li')
new_li.onclick = function(){add_marker(pt) }
return new_li;
}