I’m creating a dynamic map using Google’s API. I’m trying to get the map to dynamically apply the info boxes for each marker.. and I can’t figure it out:
http://www.zephyrusdevelopment.com/clients/electrotrack/map2.html
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It looks like you’re falling into the classic loop-plus-closure error, which in simplified form looks like this:
The problem is that, due to the way closures work in Javascript, the handler function will keep a persistent reference to the
markervariable, even after it is assigned to a new object. End result: all your handlers reference the last object assigned tomarker.There are several ways to fix this; I usually use a separate function to assign the click handler, which captures the correct
markerobject in the handler scope: