Associating correct labels with markers in Google Maps
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 h开发者_运维技巧ave 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
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).
精彩评论