Reputation: 29
I have created a zoom function for my Google maps:
function zoomIn(){
map.setZoom(parseInt(map.getZoom())+2)
}
I keep on getting a 'Object expected' error when I try to call it. When I debug this
Error: zoomIn is not defined
Source File: javascript:zoomIn()
Any ideas of why this is happening is much appreciated.
The map can be seen using the link below, the function is located on line 189
Upvotes: 1
Views: 552
Reputation: 2470
Your problem is with function scope. You define the zoomIn
function inside initialize
. When the user clicks on the control to zoom in and zoomIn()
is called it is looking for zoomIn
on the global window
object but it doesn't exist there.
To fix this you need to refactor your javascript so zoomIn
is available in the global scope. This could mean implementing the function outside of initialize()
.
Read more about JS scoping here: http://www.digital-web.com/articles/scope_in_javascript/
Upvotes: 1