Christian,

There are a couple of recommendations that I would make.

First, take a look at the scope of your variable declarations. You are
creating all of your variables at the global scope, but you may want
to consider creating certain variables with a more local scope (e.g.
declare the 'address' variable within the load function). However,
this is not causing the problem you are asking about.

Second, you are attempting to geocode each address as you are adding
the marker. A much better approach would be to do your geocoding
within your database. To do this, you have two options, either geocode
your entire database in batches, or to geocode each record as you add
it to the database. Either way, this is something you really should
consider.

Now, issue 1 and 2 may look unrelated, but together they cause the
issue you are asking about. It works like this. First, your address
variable is declared at the global space, meaning there can only ever
be 1 value assigned to this variable at a time. Now, keep in mind that
when you call geocoding, the call is asynchronous, meaning that you
have no precise idea of exactly WHEN it will return. But what's
important here is that it does take some finite time to return. In all
likelyhood, nearly 99.9% of the time, your geocoder.getLocations
callback form the first invocation (TEst property 2) will not return
until after your code has already completed with the next 'Test
Property'. In other words, your problem is related to the fact that
you are thinking synchronously, but you must realize that
geocoder.getLocations is completely asynchronous.  So what happens is
that you call geocoder.getLocations from your first marker, and the
address is set to '321 E', but by the time that getLocations returns
to addMap, your address variable (remember, there is only one), is
already set to '111 Sowers'.

Probably the best way to solve the immediate problem is to skip using
the address variable and instead use the data returned in the response
from getLocations.

I would forget using a PHP loop to write out the javascript. The best
way that I can think to accomplish what you want to do is to create a
new PHP page that returns JSON objects for you to iterate natively in
your javascript. there are many good php json packages available on
the Internet. Basically, do either one of the following:

1) just use AJAX (xmlHTTP) to make a call back to a special data page
to fetch the json
or
2) create a json variable inline using your php looping code (this
would actually work very well). In fact, with the right JSON parser,
you wouldn't even need to loop because you'd be able to create a PHP
object and then simply stream that object directly into a javascript
variable at time of request...

hope this helps....if you have any more questions about this or need
me to clarify anything, just let me know.

good luck :)


On Jul 19, 8:07 am, clhereistian <[email protected]> wrote:
> Here is a link to a page I am building:
>
> http://www.idea-machine.net/devel/apts/maps.php
>
> I am pulling addresses from a database, geocoding them, adding markers
> to a map, and then adding info windows to the markers that open when
> the markers are clicked. My problem is that each of the markers
> contain the same text, even though I reset the text before adding a
> new marker to the map.
>
> The weird part is that I set the address variable, which is used by
> the geocoder, at the same time I set the variables for the info window
> text. The markers are all placed in the correct positions, which means
> I am getting the value I expect out of the address variable. But I am
> not getting the value I expect out of the variables for the info
> window text.
>
> BTW, the reason my load function keeps resetting the address and info
> window text variables is because I am using a php loop to write the
> javascript. Maybe there is a better way to do this, but that is all I
> could think of.
>
> Thanks in advance for your help,
> Christian
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" 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-API?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to