谷歌地图不起作用

时间:2012-10-16 03:18:20

标签: javascript google-maps-api-3

我有这个简单的应用程序,将尝试加载谷歌地图。但是当我点击链接查看地图时。我收到了这个错误。

ReferenceError:未定义GBrowserIsCompatible [打破此错误]

if(GBrowserIsCompatible()){

这是我的代码

------------ scripts -------------

<script type="text/javascript" 
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyBQ8OCC8En5vNHod25Ov3Qs5E1v7NPRSsg&sensor=true">
</script>

<script type="text/javascript">
    var map;
    var geocoder;

    //Show the google map
    function initialize() {
        if (GBrowserIsCompatible()) {
            map = new GMap2(document.getElementById("divMap"));

            map.setUIToDefault();
            geocoder = new GClientGeocoder();
        }
    }

    //Show default address on map
    function showTheMap() {
        document.getElementById('divMap').style.display = "block";
        initialize();
        var address = document.getElementById("spAddress1").innerHTML;
        geocoder.getLatLng(
            address,
            function (point) {
                if (!point) {
                    alert(address + " not found");
                }
                else {
                    map.setCenter(point, 15);
                    var marker = new GMarker(point);
                    map.addOverlay(marker);
                    marker.openInfoWindow(address);
                }
            }
        );
    }
</script>

------------ HTML body ---------------

    <span id="spAddress1" runat="server" ClientIDMode ="Static"></span>
    <a onclick="showTheMap()" style="cursor: pointer;">
    <span style="text-decoration:underline;">Click here to view map </span>
    </a>

    <div id="divMap" style="display: none; width: 100%; height: 500px;top: -220px">
    </div>

谢谢

Rjuy

1 个答案:

答案 0 :(得分:0)

如果您尚未加载Google Maps API v2,则无法调用此功能GBrowserIsCompatible()。您需要获取API密钥才能执行此操作。

顺便提一下,不推荐使用Google Maps API v2。使用v3。 v3的一个优点:无需API密钥。