Internet Explorer 中的 Google Maps JavaScript API 错误

我为 Google Maps JavaScript API v3 编写了一个非常简单的 jQuery 插件.

I have written a really simple jQuery Plugin for the Google Maps JavaScript API v3.

它适用于 Firefox、Chrome(等),但不适用于 Internet Explorer 8.

It is working in Firefox, Chrome (et al), but not Internet Explorer 8.

我得到的错误是下一行的对象不支持此属性或方法"...

The error I get is "Object Doesn't Support This Property or Method" on the following line...

map = new google.maps.Map(mapContainer, myOptions);

我已经在网上发布了一个工作示例页面来演示......我正在尝试获得白金汉宫!你可以在 jquery.simplemap.js 文件中看到后面的代码,它没有被缩小.

I have put a working example page online to demonstrate... I'm attempting to get Buckingham Palace! You can see the code behind in the jquery.simplemap.js file, it isn't minified.

http://www.stevefenton.co.uk/cmsfiles/资产/文件/simplemap.html

任何帮助将不胜感激.

更新

我已经通过这段代码进行了详细的调试,它实际上在 Google 代码中出现了错误,该代码被严重缩小并且完全难以辨认 - 这就是地图加载的原因,因为错误是在地图初始化之后出现的.等我知道了我会发更多的.

I have done a detailed debug through this code and it actually errors inside the Google code, which is heavily minified and entirely illegible - this is why the map loads, as the error is after the map is initialized. I will post more when I know it.

更新2

我在插件中重新排序了各种东西,这导致地图显示正确的位置,但由于地图初始化时谷歌地图 API 深处发生的错误,我无法添加标记或标注.

I have re-ordered various things in the plugin, which results in getting the map to show the correct location, but because of the error that occurs deep in the Google Maps API when the map is initialised, I cannot add the marker or callout.

推荐答案

好的,我已经找到了解决这个问题的方法.

Okay, I have found a solution to this problem.

Google Maps API 内部引发的错误是由用于存储地图的变量的范围引起的.API 的所有示例都使用这样的东西...

The error raised from inside the Google Maps API is caused by the scope of the variable being used to store the map. All of the examples for the API use something like this...

map = new google.maps.Map(mapContainer, myOptions);

请注意,地图"是这些奇妙的神秘范围变量之一……我在我的 jQuery 插件中运行所有这些代码 - 所以最终结果是谷歌地图 API 无法处理地图变量.

Note that "map" is one of these wonderful mystery-scope variables... and I'm running all of this code inside of my jQuery Plugin - so the end result is that the Google Maps API cannot get a handle on the map variable.

通过将地图声明为全局变量,Google Maps API 可以访问它,一切都神奇地开始完美运行.

By declaring map as a Global variable, Google Maps API can access it and everything magically starts working perfectly.

所以解决方法是声明...

So the fix is to declare...

var map;

在全局范围内,因此 API 可以访问它.

In the Global scope, so the API can get to it.

相关文章