在jQuery Mobile页面中嵌入Google Map

时间:2012-04-12 06:59:26

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

我想要做的就是在jQuery移动页面的内容标记中嵌入一个护目镜地图,我无法让它出现在页面上。我猜这是一个小错误,但我已经和它搏斗了一段时间,任何帮助都会受到赞赏。

<head>
    <style type="text/css">
        #map_canvas {
            height: 256px;
            width: 384px;
            margin-top: 0.6em;
        }
    </style>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="fbObj1.js"></script>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0-rc.1/jquery.mobile-1.1.0-rc.1.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-rc.1/jquery.mobile-1.1.0-rc.1.min.js"></script>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript" src="PATH_TO_PLUGIN/jquery.ui.map.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
    />
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0-rc.1/jquery.mobile-1.1.0-rc.1.min.css"
    />
</head>

<body>
    <script type="text/javascript">
        geocoder = new google.maps.Geocoder();
        var map = new google.maps.Map($("div#map_canvas"), {
            center: new google.maps.LatLng(37.371940, -122.116470),
            zoom: 11,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        });
        map.index = 2;
    </script>
    <div data-role="page">
        <div data-role="header"></div>
        <div data-role="content">
            <div id="map_canvas"></div>
        </div>
        <div data-role="footer" data-position="inline"></div>
    </div>
</body>

1 个答案:

答案 0 :(得分:2)

以下代码适用于我

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&sensor=SET_TO_TRUE_OR_FALSE"></script>  
<script type="text/javascript">      
    function initialize() {
        var myOptions = {
            center: new google.maps.LatLng(37.371940, -122.116470),           
            zoom: 11,          
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };         
        var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
    }     
 </script> 

 <body onload="initialize()">