I’d like to populate a google map with several markers. When the user clicks on a marker I would like it to send the user to a different webpage which is designated for that location. (for example: lets say the markers represent homes, when you click on a marker it takes you to a page with more information about the home)
What is the simplest way to do this?
You will need to attach an event listener to each marker. The click handler can set
document.locationto the URL of the page you want to go to.Since you will probably be adding markers in a loop, you will need to make sure each one gets its own URL. Since closures keep the actual variables they access (not their values), you probably need to put at least
addListenercode in its own function to create its own scope. Your loop would look kind of like this: