Ok so i have a map with some markers on it. There is a click event on the map that should get the closest marker however when the find_closest_marker(event) function runs it breaks on the map.markers.length saying that its undefined.
Here is a link to what im trying to http://jsfiddle.net/VyzFq/7/
Can anyone can please show me where I’m going wrong here.
Looks like there are a couple of problems:
1) the map.markers array hasn’t been declared. declare it above the for loop, and push the markers onto the markers array.
2) the find_closest_point function can’t see the map variable. move the find_closest_point function to the scope where you are adding the click event listener: