未捕获类型错误:无法设置属性“位置”未定义 [英] Uncaught TypeError: Cannot set property 'position' of undefined

查看:1086
本文介绍了未捕获类型错误:无法设置属性“位置”未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码给我奇怪的错误信息

I have this code giving me the strange error message

Uncaught TypeError: Cannot set property 'position' of undefined

这是一个jQuery插件的内部,在弹出窗口中显示google地图。
我在别的地方使用代码,在那里它工作正常 - 唯一的区别这里似乎是,我现在使用它在一个弹出窗口。我缺少一个范围问题或什么?
像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)

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

这篇关于未捕获类型错误:无法设置属性“位置”未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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