Google Maps JavaScript API错误在Internet Explorer中 [英] Google Maps JavaScript API Error In Internet Explorer

查看:105
本文介绍了Google Maps JavaScript API错误在Internet Explorer中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



它在Firefox,Chrome(等)中工作,但不支持Internet Explorer 8,



我得到的错误是对象不支持这个属性或方法,在下面的行上...

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

我在网上放置了一个工作示例页面来演示...我试图让白金汉宫!您可以在jquery.simplemap.js文件中看到后面的代码,它不会被缩小。



http://www.stevefenton.co.uk/cmsfiles/assets/File/simplemap.html



任何帮助将不胜感激。

更新



我通过此代码完成了详细的调试,它实际上是Google代码中的错误,它严重缩小且完全无法辨认 - 这就是加载地图的原因,因为错误是在地图初始化之后。当我知道它时,我会发布更多信息。



UPDATE2



- 在插件中订购了各种东西,这会导致地图显示正确的位置,但是由于地图初始化时发生在Google Maps API深处的错误,我无法添加标记或标注。

解决方案

好的,我找到了解决这个问题的办法。

从Google Maps API内部引发是由用于存储地图的变量范围引起的。所有API的例子都是这样的...

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

请注意,map是这些神秘范围的变量之一......而我在我的jQuery Plugin中运行所有这些代码 - 所以最终的结果是Google Maps API无法获得地图变量的句柄。



通过将map声明为全球变量,谷歌地图API可以访问它,一切都神奇地开始完美。



所以修正是声明...

  var map; 

在全局范围内,API可以访问它。


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

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

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/assets/File/simplemap.html

Any help would be much appreciated.

UPDATE

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.

UPDATE2

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.

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

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.

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;

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

这篇关于Google Maps JavaScript API错误在Internet Explorer中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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