Google Maps Api 3: Uncaught TypeError: Cannot call method 'setCenter' of undefined

梦想的初衷 提交于 2020-01-02 16:56:37

问题


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

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

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

Thanks in advance.


回答1:


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).

Remove the var from var map = new google.maps.Map(...); (but not the var map; at the top).



来源:https://stackoverflow.com/questions/9636773/google-maps-api-3-uncaught-typeerror-cannot-call-method-setcenter-of-undefin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!