問題描述
我為 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.
這篇關于Internet Explorer 中的 Google Maps JavaScript API 錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!