2013-08-28 89 views
1

我是新來的移動程序,並試圖從谷歌地圖V3教程,谷歌Android的地圖

<!DOCTYPE html> 
<html> 
<head> 
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
    <script type="text/javascript"> 
     function initialize() { 
      alert('init'); 
      var latlng = new google.maps.LatLng(-34.397, 150.644); 
      var myOptions = { 
       zoom: 8, 
       center: latlng, 
       mapTypeId: google.maps.MapTypeId.ROADMAP 
      }; 
      var map = new google.maps.Map(document.getElementById("map_canvas"), 
     myOptions); 
     } 
     var myKey = "mykey"; 
     function loadScript() { 
      var script = document.createElement('script'); 
      script.type = 'text/javascript'; 
      script.src = "https://maps.googleapis.com/maps/api/js?key="+myKey+"&sensor=false&callback=initialize"; 
      document.body.appendChild(script); 
     } 
    </script> 
</head> 
<body onload="loadScript()"> 
    <div id="map_canvas" style="width: 400px; height: 400px"> 
    </div> 
</body> 
</html> 

我想這用我的電腦在netbean,一切正常,但是當我下載到我的Android設備(作爲應用程序),回調函數(初始化)永遠不會被調用。任何人都知道這有什麼問題?

感謝

+0

你有沒有啓動Javascript在你的Android設備上(瀏覽器可能會禁用它)檢查設置。 – Guru

+0

是我有我的Android設備上啓用了JavaScript。 – CodeGuru

回答

0

首先關閉所有下載手機差距插件

<!DOCTYPE html> 
<html> 
    <head> 
    <title>Simple Map</title> 
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> 
    <meta charset="utf-8"> 
    <style> 
     html, body, #map-canvas { 
     height: 100%; 
     margin: 0px; 
     padding: 0px 
     } 
    </style> 
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script> 
    <script> 
var map; 
function initialize() { 
    var mapOptions = { 
    zoom: 8, 
    center: new google.maps.LatLng(-34.397, 150.644), 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    map = new google.maps.Map(document.getElementById('map-canvas'), 
     mapOptions); 
} 

google.maps.event.addDomListener(window, 'load', initialize); 

    </script> 
    </head> 
    <body> 
    <div id="map-canvas"></div> 
    </body> 
</html> 

嘗試運行在移動/仿真器上面的代碼,那麼你可以有樣圖顯示