Search code examples
javascriptjquerygoogle-mapscordovajqtouch

Can't display Google map with jqTouch and PhoneGap


I'm fighting with this issue for a long time now and I can't find a proper solution. My goal is to display a Google map in my app. I'm developing my app with jQTouch and PhoneGap framework. Here is my code:

<!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>

The problem is that the map won't display no matter what I'm trying. I tried every hint that I found here on Stack Overflow but no luck so far. Any help would be appreciated.


Solution

  • You need to set the height of the container div in px instead of %

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

    Try this and the map will show up. Also make sure the initialize method is being called.