ChrisD
ChrisD

Reputation: 29

Google Maps V3 cannot call function from infowindow

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

http://tinyurl.com/3ryuxvy

Upvotes: 1

Views: 552

Answers (1)

Jake
Jake

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

Related Questions