PhoneGap谷歌地图 - 地图不显示

时间:2012-11-04 20:57:41

标签: android google-maps cordova

我正在编写一个使用PhoneGap的应用程序,需要在其中集成Google地图。我使用了Google提供的在线文档中的这个示例:

   <!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 0; padding: 0 }
      #map_canvas { height: 100% }
    </style>
    <script type="text/javascript"
      src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDlFl3vPEbgzrr-1KX5E20z_1DowB2ASus&sensor=true">
    </script>
    <script type="text/javascript">
      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);
      }
    </script>
  </head>
  <body onload="initialize()">
    <div id="map_canvas" style="width:100%; height:100%"></div>
  </body>
</html>

如果我在网络浏览器中打开它(Chrome,FF,IE ...),这项工作正常。但是,在我的模拟器(以及设备)中,它只显示一个空白页面。有什么提示吗?

1 个答案:

答案 0 :(得分:6)

由于我在同一个应用程序上使用多个html页面,因此出现此问题。由于phonegap将使用ajax调用来替换索引页面的dom,因此它也无法在这些页面上加载脚本。

这里有两种解决方案:

  1. 仅使用单个html页面
  2. 使用

    加载第二页

    的rel = “外部”

相关问题