为什么我不能在jquery mobile中加载我的谷歌地图?

时间:2012-05-27 00:38:00

标签: jquery-mobile google-maps-api-3

我在打开此页面的链接上执行rel =“external”,因此DOM重新加载应该排除很多问题。

尽管如此,使用以下代码我得到一个巨大的红色背景,页面和页脚很好 - 尽管函数调用,但地图仍然没有初始化。谁能发现问题?这个bug一直让我失望;我已经尝试了一百万件事情,包括重新设计它作为多重模板而没有rel =“external”,但这也不起作用。

<!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css"/>
        <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
        <script type="text/javascript">
            $(function(){initializeMap(42,-73);});

            function initializeMap(lat,lng) {
                var latlng = new google.maps.LatLng(lat, lng);
                var myOptions = {
                zoom: 8,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
            var crosshairLayer = new google.maps.KmlLayer('http://freezoo.alwaysdata.net/justcrosshair2.kml',
            {preserveViewport: true});

            crosshairLayer.setMap(map);

            google.maps.event.trigger(map, 'resize');
            map.setZoom( map.getZoom() );
            }
        </script>
    </head>
    <body>
        <div data-role="page" data-theme="e" data-add-back-btn="true" class="map1" id="testing">
            <div data-role="header"><h1>Map Page</h1></div>
            <div id="content" style="position:absolute; bottom:40px; top:40px; left:0px; right:0px; background:green;"> 
                <div id="map_canvas" style="position:absolute; top:0px; bottom:0px; width:100%; background:red;"></div>
            </div>
            <div data-role="footer" style="position:absolute; bottom:0px; width:100%;">
                <h1>Working!</h1>
            </div>
        </div>
    </body>
</html>

1 个答案:

答案 0 :(得分:2)

您的代码未加载Google地图脚本。像这样举例如:

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
相关问题