最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google Maps API v3 BrowserIsCompatible - Stack Overflow

programmeradmin3浏览0评论

I'm updating some older code that used the v2 API for Google Maps. On domready, it would use a statement like

if(google.maps.BrowserIsCompatible()){
// load the map
}

Now that I'm loading the Google Maps API v3, I get an error

google.maps.BrowserIsCompatible is not a function

I've read a ton of threads in the Google v3 api groups, but haven't found a clear answer of what the new function is called or how to reference it.

I'm updating some older code that used the v2 API for Google Maps. On domready, it would use a statement like

if(google.maps.BrowserIsCompatible()){
// load the map
}

Now that I'm loading the Google Maps API v3, I get an error

google.maps.BrowserIsCompatible is not a function

I've read a ton of threads in the Google v3 api groups, but haven't found a clear answer of what the new function is called or how to reference it.

Share Improve this question edited Nov 25, 2011 at 20:42 skaffman 404k96 gold badges824 silver badges775 bronze badges asked Aug 18, 2010 at 23:15 juliojulio 6,76815 gold badges65 silver badges82 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

GBrowserIsCompatibile didn't make it into the version three API, so you will have to write this code yourself.

Here is a list of the browsers supported by v3.

There is no equivalent of this method in V3 as of Google's V2 to V3 migration doc.

Instead, an efficient way to achieve this test is:

if (window.JSON) {
    // load google maps api async (so google.maps object is available for further use)
}

That's because all the browsers that Google Maps API V3 support share that same particularity : they are the first versions (by their vendor) that supports JSON natively. See this screenshot taken from caniuse.:

Exceptions:

Firefox 3.0 and BlackBerry Browser 6 don't support JSON but are supported by Google Maps API. So the rule above will exclude both, which is an acceptable drawback for such a simple test (pared to a user-agent-sniffing-based code)

Notice:

this test doesn't apply to 'google.maps' object but at script load time. This prevents cases (e.g IE6) when the script is successfully loaded but 'google.maps' object unusable.

发布评论

评论列表(0)

  1. 暂无评论