开发者

Google Maps API JavaScript error when GBrowserIsCompatible() is called

I get an error on the following line:

 if (GBrowserIsCompatible()开发者_如何学C) {

this is my code still not working

<script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;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>


Did you load the Google Maps API with your own API key?

<script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ENTER_API_KEY_HERE'></script>

Source: 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.


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.


I too had the Same Issue. When i checked with the Example program at http://universimmedia.pagesperso-orange.fr/geo/loc.htm it 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.


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.

Google Maps v2 to v3: Removing Obsolete Code

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜