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
Your problem is with function scope. You define the
zoomInfunction insideinitialize. When the user clicks on the control to zoom in andzoomIn()is called it is looking forzoomInon the globalwindowobject but it doesn’t exist there.To fix this you need to refactor your javascript so
zoomInis available in the global scope. This could mean implementing the function outside ofinitialize().Read more about JS scoping here: http://www.digital-web.com/articles/scope_in_javascript/