我試圖使用StageWebView
來顯示使用JavaScript API生成的Google地圖地圖。是否有理由不在iOS上呈現?它適用於Android和AIR模擬器,但不適用於iOS設備。我也可以查看Safari中生成的HTML,這使得它更加怪異。使用StageWebView.loadString()在iOS上顯示Google地圖
例HTML(我動態應用程序內生成這個,這不是問題):
<!DOCTYPE HTML>
<html style="width:100%; height:100%; margin: 0; padding: 0;">
<head>
<title></title>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(e){
var myLatlng = new google.maps.LatLng(0,0);
var mapOptions = {
zoom: 18,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.DEFAULT
}
}
var map = new google.maps.Map(document.getElementById("maps") , mapOptions);
geocoder = new google.maps.Geocoder();
geocoder.geocode({ "address": "90 South Kyrene, Chandler, AZ 85226" }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
}
});
});
</script>
</head>
<body style="width:100%; height:100%; margin: 0; padding: 0;">
<div id="maps" style="width:100%; height:100%; margin: 0; padding: 0;"></div>
</body>
</html>
我使用StageWebView.loadString(html, "text/html");
加載它。任何想法爲什麼它不呈現?加載URL似乎工作(所以我會嘗試將HTML保存到磁盤並加載,接下來)罰款,只是不loadString。
測試雙方的iOS 6和iOS 7,並用AIR 3.8和3.9
編輯: 作爲後續行動,保存HTML文件到磁盤,然後加載一個通過StageWebView.loadURL()
作品就好了。但仍然好奇,爲什麼通過loadString()
加載它不起作用。
這是我認爲發生的事情。 iOS會阻止應用程序執行JS是有道理的。無論如何,通過將文件保存到磁盤上的方式是很好的。過去我使用過MapQuest API,而且我一直覺得它的加載速度很慢。不過,我可能會使用它,因爲使StageWebView在滾動條中正常工作幾乎是不可能的。無論如何,我會將你的標記標記爲正確的。迄今爲止我見過的最佳答案。謝謝。 –