无法使用jqTouch和PhoneGap显示Google地图

时间:2013-02-21 17:48:35

标签: javascript jquery google-maps cordova jqtouch

我现在很长时间都在与这个问题作斗争,我找不到合适的解决方案。我的目标是在我的应用中显示Google地图。我正在使用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…“</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上找到的每一个提示但到目前为止没有运气。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

您需要以px而不是%

设置容器div的高度
<div id="map_canvas" style="width:100%; height:100px"></div>

试试这个,地图会显示出来。还要确保调用initialize方法。