调用 GBrowserIsCompatible() 时出现 Google Maps API JavaScript 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5091721/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Google Maps API JavaScript error when GBrowserIsCompatible() is called
提问by shanmugavel-php
I get an error on the following line:
我在以下行中收到错误消息:
if (GBrowserIsCompatible()) {
this is my code still not working
这是我的代码仍然无法正常工作
<script src="http://maps.google.com/maps?file=api&v=2.x&key=<?php echo $google_api['VALUE'];?>" type="text/javascript"></script>
<script type="text/javascript">
var map = null;
var geocoder = null;
function initialize(address) {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
geocoder = new GClientGeocoder();
/* Start */
if (geocoder) {
geocoder.getLatLng(
address,
function (point) {
if (!point) {
alert(address + " not found");
} else {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(address);
}
}
);
}
/* End */
}
}
</script>
回答by nyuszika7h
Did you load the Google Maps API with your own API key?
您是否使用自己的 API 密钥加载了 Google Maps API ?
<script src='http://maps.google.com/maps?file=api&v=2&key=ENTER_API_KEY_HERE'></script>
Source: http://code.google.com/p/jmaps/issues/detail?id=12
来源:http: //code.google.com/p/jmaps/issues/detail?id=12
Update
更新
Check out the troubleshooting page for IE.
Maybe you're checking for it too early. Try something like this:
也许你检查得太早了。尝试这样的事情:
var iterations = 0;
function check_compat() {
if (iterations === 75) {
alert('Failed to load Google Maps API. Clear your browser cache, open Google Maps then try again.');
return;
}
if (typeof GBrowserIsCompatible === 'undefined') {
// It isn't loaded, schedule the next check.
setTimeout(check_compat, 200);
iterations++;
} else {
if (GBrowserIsCompatible()) {
mapReadyFn();
} else {
alert('Sorry, your browser is not supported.');
}
}
}
After that, just replace this line:
之后,只需替换此行:
if (GBrowserIsCompatible()) {
with this:
有了这个:
function mapReadyFn() {
If it fails for 15 seconds, it stops trying and you get an error.
如果它失败了 15 秒,它就会停止尝试并且你会得到一个错误。
回答by Marcin
I've had the same problem with internet explorer if the page was viewed with https protocol (instead of http). Are you using it via https or http? Anyway with https there will be warnings unless you pay something like 10 000$ to google.
如果使用 https 协议(而不是 http)查看页面,那么 Internet Explorer 也会遇到同样的问题。您是通过 https 还是 http 使用的?无论如何,使用 https 都会有警告,除非您向 google 支付 10 000 美元之类的费用。
回答by Mohanram gandhi
I too had the Same Issue. When i checked with the Example program at http://universimmedia.pagesperso-orange.fr/geo/loc.htmit was Working fine; but When i Changed the API Key Value to that of mine, I got the Error at Gbrowser Line., After checking with my Google Account API., I realized that there are two Google Map API Versions 2 & 3 AND I have enabled only 3 and was referring the Map in the java Script., When i Enabled the API Version 2., The error is Fixed. Try it out and give your feedback.
我也有同样的问题。当我在http://universimmedia.pagesperso-orange.fr/geo/loc.htm检查示例程序时,它工作正常;但是当我将 API 密钥值更改为我的值时,我在 Gbrowser Line 处收到错误。在检查我的 Google 帐户 API 后,我意识到有两个 Google Map API 版本 2 和 3,而我只启用了 3 个并在 java 脚本中引用地图。当我启用 API 版本 2 时,错误已修复。尝试一下并提供您的反馈。
回答by Jasman
The answer from @Andrew S now seems to be the best, since v3 is now the only available version of the API. There is no GBrowserIsCompatible method, nor is there any replacement. I'd guess it would be best to check some web APIs (e.g., geolocation) you intend to use before invoking maps APIs.
@Andrew S 的答案现在似乎是最好的,因为 v3 现在是 API 的唯一可用版本。没有 GBrowserIsCompatible 方法,也没有任何替代方法。我想最好在调用地图 API 之前检查一些您打算使用的 Web API(例如,地理定位)。

