0

所以我的代码似乎不起作用。它没有说无效的密钥或任何东西。它只是空白。你能看看我的代码找出问题所在吗?谢谢你。

    <!DOCTYPE HTML>
<html>
    <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?key=MYKEYDOESNTDISPLAYERRORS&sensor=false"></script>

    <script src="js/jquery.min.js"></script>
    <script type="text/javascript">
        function initialize() {
            var latlng = new google.maps.LatLng(57.0442, 9.9116);
            var settings = {
                zoom: 15,
                center: latlng,
                mapTypeControl: true,
                mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
                navigationControl: true,
                navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
                mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"), settings);

    </script>
</head>
<body onload="initialize()">
    <div id="map_canvas" style="width: 800px; height: 600px; margin: auto;">
    </div>
</body>

4

1 回答 1

0

设置变量没有右括号。设置变量也与实例化地图的全局调用不在同一范围内 - 即使是,地图变量实例化也会在调用 initialize() 之前发生。试试这个:

<script type="text/javascript">
    var map;
    function initialize() {
        var latlng = new google.maps.LatLng(57.0442, 9.9116);
        var settings = {
            zoom: 15,
            center: latlng,
            mapTypeControl: true,
            mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
            navigationControl: true,
            navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById("map_canvas"), settings);
    };

</script>
于 2012-07-20T17:04:54.263 回答