2012-06-07 29 views
0

有人可以看看我的代碼並告訴我我做錯了什麼嗎?我花了很多時間嘗試不同的事情,但都沒有成功。坦克給每個可以幫助我的人!jQuery Mobile Google地圖 - 地圖僅在重新載入後顯示

  • 調用這個頁面直接作用
  • 呼籲從以前的頁面此頁面鏈接類型「外部」的作品
  • 調用該側通常是從一個jQueryMobile頁面這一項,不能正常工作,並顯示地圖空,再點擊刷新後,一切都是完美的

代碼:

<html> 
<head> 
    <meta charset="UTF-8"> 
      <meta name="viewport" content="minimum-scale=1.0, width=device-width, maximum-scale=1.0, user-scalable=no" /> 
    <meta name="apple-mobile-web-app-capable" content="yes"> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" /> 
     <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> 
     <script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script> 
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true&libraries=places"></script> 
</head> 
<body> 
<div data-role="page" id="basic_map"> 
     <script type="text/javascript"> 
     $("div:jqmData(role='page'):last").bind('pageinit', function() { 
      if(navigator.geolocation) { 
         navigator.geolocation.getCurrentPosition(function(position){ 
          initialize(position.coords.latitude,position.coords.longitude); 
         }); 
       } 
      }); 

      function initialize(lat,lng) { 

      var latlng = new google.maps.LatLng(lat, lng); 

      var myOptions = { 

       zoom: 12, 
         center: latlng, 
         mapTypeId: google.maps.MapTypeId.ROADMAP 
       }; 

      var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions); 

</script> 

    <div data-role="header" data-theme="b" data-position="fixed" data-inset="false"> 
      <h1>My</h1> 
     <a href="index.html" data-icon="home" class="ui-btn-right" data-iconpos="notext" >Home</a> 
     </div> 

    <div data-role="content"> 

      <h4>Map</h4> 

     <div class="ui-bar-c ui-corner-all " > 
      <div id="map_canvas" style="height:300px;"></div> 
     </div> 
    </div> 
    </div> 
</body> 
</html> 

回答

0

- 編輯 - 忘記我說的話。你說得對,它不能解決問題。 :)

看來你已經忘記關閉你的34行上的初始化()函數!不要忘記的方式放置文檔類型,那麼這將是35行

我現在看到的地圖馬上我的機器上(鉻19)

+0

1)我試圖將我現有的Java腳本恰到好處前 - >沒有變化,同樣的問題,像 2) 之前,我改變了功能,開始爲你在這種情況下,上述 描述即使我重新加載頁面,地圖不再顯示:-) 我完全困惑,不知道,.... ;-) – Reinhard

+0

你是對的。我更新了我的答案!謝謝你的代碼片段。我現在實際上正在開發一個JQM應用程序,只需要一些關於用戶位置的信息。你的例子是完美的現在,我已經得到它的工作。 :D – Sephie

+0

我知道它的運行良好,.... 關閉,它的複製錯誤,我已經在我的源關閉 正如我所說,它的工作原理,很好,除非你來自另一個JQuery頁面之前 然後java腳本不加載 – Reinhard

0

好了,這個問題原來是給予this question的答案的確切副本。我不確定它爲什麼不能在你身邊工作,因爲我現在使用的是相同的代碼。

我確實遇到了我的地圖偏離中心的小故障,但是通過將pageinit替換爲pageshow來解決問題。對於我來說,重新加載頁面,甚至改變瀏覽器的窗口寬度都可以修復它。

您的地圖是完全不可見的,還是您可以在左上角看到什麼?