繁体   English   中英

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

[英]Can't display Google map with jqTouch and PhoneGap

我为此问题已经斗争了很长时间,但找不到合适的解决方案。 我的目标是在我的应用中显示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上找到的所有提示,但到目前为止还没有运气。 任何帮助,将不胜感激。

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

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

试试这个,地图就会显示出来。 还要确保初始化方法被调用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM