views:

224

answers:

1

Hi - I have a little problem with a Google Maps page I have put together. Here is the test URL - http://projects.presencemultimedia.co.uk/impari/savings/map_test.html

I want to have multiple locations plotted on the map by referencing their UK postcode. Each marker will also have an associated label when the user clicks the marker (using openInfoWindowHtml).

The test page plots the markers fine, but I'm struggling to get the correct label to appear for each marker. Currently when you click on the marker they all show the label of the last marker plotted.

Not sure if I've just got confused by variable scope in javascript or if there is some peculiarity with multiple markers in Google Maps but this has driven me mad for a little while now!

Any help/advice greatly appreciated!

Regards, Phil

+1  A: 

The problem is that when you callback function is being called asynchronously, the global infoHTML variable has been set to "Village Farm Health Club" which is why you are always seeing that as the info window text.

You need to pass the info window html into usePointFromPostcode, associate it with a local GlocalSearch object and then pass that into the callbackFunction.

Here is a working version of this example (based on your code) (source).

Cannonade
Thanks - I thought it must be a problem with the scope of the variable. An example link will be great. Regards.
Phil
My mistake, sorry
Kaze no Koe
Many thanks - worked a treat ;-) Regards
Phil
No problem. Happy to help.
Cannonade