问题描述
我有这段代码给了我奇怪的错误信息
I have this code giving me the strange error message
Uncaught TypeError: Cannot set property 'position' of undefined
这是一个 jQuery 插件的内部,用于在弹出窗口中显示谷歌地图.我在其他地方使用了代码,在那里它运行良好 - 这里唯一的区别似乎是我现在在弹出窗口中使用它.我错过了范围问题还是什么?像 geocoderParams 和 latlng 这样的所有变量都按应有的方式填充.谷歌搜索错误消息没有发现任何有价值的东西.
This is the inside of a jQuery plugin to show a google map in a popup.I was using the code somewhere else, where it worked fine - the only difference here seems to be that I'm now using it in a Popup window. Am I missing a scope issue or something?All the variables like geocoderParams and latlng are filled like they should.Googling the the error message turned up nothing valuable.
调用 google.maps.Map() 时会触发错误消息.
The error message gets fired when the google.maps.Map() is called.
self = $(this)
self.hide()
geocoder = new google.maps.Geocoder
geocoderParams =
address: self.data('address') || settings.address
region: settings.region
results = geocoder.geocode geocoderParams, (results, status) ->
if status == google.maps.GeocoderStatus.OK
latlng = results[0].geometry.location
mapOptions =
mapTypeControl: false
overviewMapControl: false
zoom: settings.zoomLevel
center: latlng
mapTypeId: google.maps.MapTypeId.ROADMAP
map = new google.maps.Map(self, mapOptions)
self.show()
推荐答案
我查找了 google.maps.Map()
和 Google 参考 说第一个参数应该是 mapDiv:Node
,它是地图,通常是一个 div
元素.
I looked up google.maps.Map()
and the Google reference says that the first parameter should be a mapDiv:Node
which is the container for the map and is typically a div
element.
您正在传递 $(this)
,它可能是一个 jQuery 对象,它不是谷歌地图所期望的.我不知道你的其余代码,但也许你应该只传递 this
而不是 $(this)
.
You are passing $(this)
which is likely a jQuery object which is not what Google maps is expecting. I don't know the rest of your code, but perhaps you should just be passing this
instead of $(this)
.
这篇关于未捕获的类型错误:无法设置未定义的属性“位置"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!