1

我创建了一个名为的 PHP 文件maps.php,其中包含一个在 iPad 的默认浏览器上运行的简单 Google Maps API。

但是当我使用 Ajax 调用它时,页面会自行加载,而不是地图。如果我在桌面或移动浏览器中打开链接,它可以正常工作。

4

1 回答 1

2

您可以通过访问 google 的javascript api来显示 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="http://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&sensor=SET_TO_TRUE_OR_FALSE">
    </script>
    <script type="text/javascript">
      function initialize() {
        var myOptions = {
          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"),
            myOptions);
      }
    </script>
  </head>
  <body onload="initialize()">
    <div id="map_canvas" style="width:100%; height:100%"></div>
  </body>
</html>

或者您可以使用window.location="http://www.mourady.me/alhokair/iphone/maps.php"javascript 方法直接在 webView 中加载任何 php 页面,因为您的 php 页面在 canvas 标签中包含谷歌地图,您不能通过 ajax 调用将其加载到 div 中,更好的方法是使用 iframe 标签来工作。

<html>
    <body onload="bodyload()">
        <button onclick="bodyload()">Ajax call</button>
        <iframe id="mapDiv" height=500px width=700px src="http://www.mourady.me/alhokair/iphone/maps.php"></iframe>
    </body>
</html>
于 2012-05-07T07:54:27.700 回答