Google Maps Api 3: Uncaught TypeError: Cannot call

2019-05-29 00:34发布

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条回答
叛逆
2楼-- · 2019-05-29 01:32

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

查看更多
登录 后发表回答