0

我与这个问题斗争了很长时间,但我找不到合适的解决方案。我的目标是在我的应用中显示谷歌地图。我正在使用 jQTouch 和 PhoneGap 框架开发我的应用程序。这是我的代码:

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 0; padding: 0 }
      #map_canvas { height: 100% }
    </style>
    <!-- INCLUDE CORDOVA -->
    <script type="text/javascript" src="cordova-2.4.0.js"></script>
    <!-- INCLUDE REMOTE DEBUGGING -->
    <script src="http://debug.phonegap.com/target/target-script-min.js#photogap"></script>"
    <!-- INCLUDE jQTouch -->
    <link rel="stylesheet" href="./js/jqtouch-1.0-b4-rc/themes/css/jqtouch.css" id="jqtcss" />
    <link rel="stylesheet" href="./css/index.css" />
    <script type="text/javascript" src="./js/jqtouch-1.0-b4-rc/src/lib/zepto.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/jqtouch-1.0-b4-rc/src/jqtouch.min.js" charset="utf-8"></script>
    <!-- INCLUDE GOOGLE MAP -->
    <script type="text/javascript"
      src="https://maps.googleapis.com/maps/api/js?key=AIzaSyByqhQ9cCaXTKjBi2xEyp_HqQJwDl3YzRo&sensor=true">
    </script> 
    <script type="text/javascript">
        // Inicializuj jqTouch
        $.jQTouch({
            icon: 'jqtouch.png',
            statusBar: 'black-translucent',
            preloadImages: []
        });

    </script>
  </head>
  <body>
    <div id="home" class="current">
        <div class="toolbar">
            <h1>Orionids</h1>
        </div>
        <ul class="rounded">
            <li class="arrow"><a href="#my_spots">My Spots</a></li>
            <li class="arrow"><a href="#map">View On Map</a></li>
            <li class="arrow"><a href="#" onclick="choosePhoto(pictureSource.PHOTOLIBRARY)">Choose From Library</a></li>
        </ul>
        <div id="spot_btn">
            <a href="#" class="redButton" onclick="takePhoto()">Spot Now!</a>
        </div>
        <p id="quote">„Make a wish…“&lt;/p>
    </div>
    <div id="map">
        <div class="toolbar">
            <h1>Map View</h1>
            <a class="back" href="#">Home</a>
        </div>
        <div id="map_canvas" style="width:100%; height:100%"></div>
        <script>
        // Incializuj Google Mapy
        function initialize() {
            var mapOptions = {
                    center: new google.maps.LatLng(-34.397, 150.644),
                    zoom: 8,
                    mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            var map = new google.maps.Map(document.getElementById("map_canvas"),
            mapOptions);
        }

            $('#map').bind('pageAnimationEnd', function() {
                initialize();
            });
        </script>
    </div>
  </body>
</html>

问题是无论我尝试什么,地图都不会显示。我尝试了在 Stack Overflow 上找到的所有提示,但到目前为止还没有运气。任何帮助,将不胜感激。

4

1 回答 1

1

您需要以 px 而不是 % 设置容器 div 的高度

<div id="map_canvas" style="width:100%; height:100px"></div>

试试这个,地图就会出现。还要确保正在调用初始化方法。

于 2013-02-21T20:34:13.357 回答