"Zoom here" link resulting in "ReferenceError: Can't find variable" JavaScript error

157 views
Skip to first unread message

Michæl

unread,
Aug 31, 2011, 5:31:51 PM8/31/11
to Google Maps JavaScript API v3
re http://mvjantzen.com/flickr/problem.html

This page was generated by a PHP program I'm writing. I copied the
output to a separate static HTML file to make it easier to debug.

When you click on a red icon, the InfoWindow includes a Flickr image
and a "zoom here" link. That HREF goes to:

javascript:map.setCenter(point3)

-which results in the JavaScript error "ReferenceError: Can't find
variable: map". Map was defined as

var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);

-and references to it else work. So, the problem seems to be one of
context and scope.

How do I fix that javascript call so the browser can find the "map"
object and call setCenter?

geoco...@gmail.com

unread,
Aug 31, 2011, 8:15:52 PM8/31/11
to Google Maps JavaScript API v3
On Aug 31, 2:31 pm, Michæl <mvs...@gmail.com> wrote:
> rehttp://mvjantzen.com/flickr/problem.html
Make it global (for more details see Mike Williams' explanation of
javascript variable scope in his v2 tutorial).

Currently it is local to your initialize function.

Change:
function initialize() {
...
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);

To:
var map = null;
function initialize() {
...
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);

-- Larry
Reply all
Reply to author
Forward
0 new messages