Google Groups Home
Help | Sign in
multiple results with new GLatLng
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
dms  
View profile
 More options Apr 30, 7:17 pm
From: dms <diegui...@gmail.com>
Date: Wed, 30 Apr 2008 16:17:22 -0700 (PDT)
Local: Wed, Apr 30 2008 7:17 pm
Subject: multiple results with new GLatLng
hi there. im getting an address search results in this way... (with
JSON)

...
var data = transport.responseText.evalJSON(true);
for(i=0;i<=data.Placemark.length-1;i++){
     addressPoint = new
GLatLng(data.Placemark[i].Point.coordinates[1],data.Placemark[i].Point.coor dinates[0]);

     new_li = document.createElement('li')
     new_li.onclick = function(){
          add_marker(addressPoint)
     }
     document.getElementsById('ul')[0].appendChild(new_li)

}

function add_marker(where){
     var draggableMarker = new GMarker(where, {draggable: true});
     map.addOverlay(draggableMarker);
     map.panTo(where, 14);
}

...

in other words... im sending addressPoint (GLatLang) to the add_marker
function instead of sending one parameter to lat and other to lng.

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.
thx so much!


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Barry Hunter  
View profile
 More options Apr 30, 7:28 pm
From: "Barry Hunter" <barrybhun...@googlemail.com>
Date: Thu, 1 May 2008 00:28:16 +0100
Local: Wed, Apr 30 2008 7:28 pm
Subject: Re: multiple results with new GLatLng
I dont think you are obtaining function closure propelly on the
clustermarker variable,
http://econym.googlepages.com/closure.htm
have a look at the more standard (and working) createMarker functions,
that create it, return it and then you add it the map.

But in anycase you really should provide a link to your map - that
will almost certainly get you a far better answer.

--
Barry

- www.nearby.org.uk - www.geograph.org.uk -


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
warden [Andrew Leach - Maps API Guru]  
View profile
 More options Apr 30, 7:32 pm
From: "warden [Andrew Leach - Maps API Guru]" <andrew.leac...@googlemail.com>
Date: Wed, 30 Apr 2008 16:32:35 -0700 (PDT)
Local: Wed, Apr 30 2008 7:32 pm
Subject: Re: multiple results with new GLatLng
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;
     }


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dms  
View profile
 More options May 1, 1:47 pm
From: dms <diegui...@gmail.com>
Date: Thu, 1 May 2008 10:47:32 -0700 (PDT)
Local: Thurs, May 1 2008 1:47 pm
Subject: Re: multiple results with new GLatLng
the helper function is what i need, thx guys!

On 30 abr, 20:32, "warden [Andrew Leach - Maps API Guru]"


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google