Google Maps API v3 BrowserIsCompatible
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 Map开发者_运维百科s 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.
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.com:
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 (compared 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.
精彩评论