Google Maps Api 3:未捕获的TypeError:无法调用未定义的方法"setCenter" [英] Google Maps Api 3: Uncaught TypeError: Cannot call method 'setCenter' of undefined

查看:77
本文介绍了Google Maps Api 3:未捕获的TypeError:无法调用未定义的方法"setCenter"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力使我的地址解析器能够在以下网址工作,但似乎无法弄清楚我做错了什么:

I have been trying to get my geocoder working this morning for the following URL but can't seem to figure out what I am doing wrong: http://www.dlplaw.com/media/map.html

单击编码"时,地理编码器正在执行其工作,并返回正确的纬度/经度坐标,但挂在setCenter上.

When clicking encode, the geocoder is doing it's job and returning the correct Lat / Long coordinates but it gets hung up on setCenter.

Uncaught TypeError: Cannot call method 'setCenter' of undefined

我试图在此处遵循Google的示例,但无法理解为什么它不起作用: http://code.google.com/apis/maps/documentation/javascript/examples/geocoding-simple.html

I tried to follow the Google example here and can't understand why this won't work: http://code.google.com/apis/maps/documentation/javascript/examples/geocoding-simple.html

谢谢.

推荐答案

map 不在范围内.您两次声明 map –一次在全局范围内,一次在 initialize 中,但是您只能在 initialize 中设置 map (全局 map 被遮盖).

map is not in scope. You declare map twice – once in the global scope and once in initialize, but you only set the map in initialize (the global map is shadowed).

var map = new google.maps.Map(...); (但不是 var map; 在顶部).

这篇关于Google Maps Api 3:未捕获的TypeError:无法调用未定义的方法"setCenter"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆