English 中文(简体)
无法用 jQuery Mobile 显示谷歌地图吗?
原标题:Can t display Google Map with jQuery Mobile?

运行时, 如果我单击索引页底部的链接到达地图页, 我可以看到地图, 填满屏幕的四分之一, 在它消失之前。 我做错什么了?

这是索引页的代码, 创建地图页 :

<!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" charset="utf-8" src="phonegap-1.4.1.js"></script>          
        <script type="text/javascript">
            function initialize(){
                if(!window.navigator.onLine){
                    alert("An internet connection is required to use the MetPetDB App. Please find a connection and reopen the app.");
                    var element = document.getElementById("mainPage");
                    element.parentNode.removeChild(element);
                    document.getElementById("mainBody").innerHTML = "<p>An internet connection is required to use this app.</p>";
                }
            }
        </script>
        <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">   </script> 
        <script type="text/javascript">
            // When map page opens get location and display map
            $( .page-map ).live("pagecreate", 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);
            }
        </script>
    </head>
    <body id="mainBody" onload="initialize()">
        <div id="mainPage" data-role="page" data-theme="e">
            <div data-role="header">
                <!-- <img src="headerlogo.png" />-->
                <br />
                <p style="text-align:center">To begin searching for samples, select one of the following search methods.</p>
            </div>
            <div data-role="content" style="height: 100%;">
                <a data-role="button" data-theme="a" href="useMyLocation.html">Use My Location</a>
                <a data-role="button" data-theme="a" href="InputCoordinates.html">Input Coordinates</a>
                <a data-role="button" data-theme="a" href="selectRegion.html">Select Region</a>
                <a href="dragMap.html">Testing</a>
           </div>
       </div>
    </body>  
</html>

这是地图页:

<!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
    </head>
    <body>
        <div data-role="page" data-theme="e" class="page-map" style="width:100%; height:100%;">
            <div data-role="header"><h1>Map Page</h1></div>
            <div data-role="content" style="width:100%; height:100%; padding:0;"> 
                <div id="map_canvas" style="width:100%; height:100%;"></div>
            </div>
        </div>
    </body>
</html>
最佳回答

以下代码有效 : < a href=" "http://jsfiddle.net/5hR9x/" rel=" nofollow" >jsfiddle

我拿走了你的代码,简化了它(使用一个单页模板,而不是多页模板,但只是为了方便jsfiddle),并移动了头部内的所有脚本。

使用电话时要小心, 您应该处理 DeviceReady 上的事件, 而不是载体事件。 即使如此, 也有一个 < a href=" http:// www. neotericdeign.com/blog/ checking-the- on- line- status- with- honegap- jquery" rel= “ nofollow” > 不同的方法 来检查您是否在线 。

问题回答

暂无回答




相关问题
Why do I get "map.set_center is not a function"?

This code have been working until I updated last night. The code works perfectly on my localhost, but I get an error on my test server. The error message (from Firebug) is "map.set_center is not a ...

The state of GMaps v3

I m about to start a Google map based project and am wondering if the release version of GMaps v3 has most of the features that are available in v2, or if it would be best to stick with v2 for now. Is ...

Bouncy marker in Google Maps v3

In Google Maps API v2 we can set to marker an option bouncy:true. It adds to marker eye-candy ability - after dragging this marker, it is bouncing. Is it possible to do in API v3 ?

GUnload() a single Google Map

I ve got some Javascript/HTML code which displays a variable number of maps dependent on what the user selects. I ve worked how to dynamically create multiple maps on a page - that s well documented. ...

How to change Gmap markers color?

I ve a custom google map with different points: Markers[0] = new Array(new GMarker(new GLatLng(45.0, 9.0)), "Location1", "<strong>Address Line</strong><br/>Some information"); ...

热门标签