我试图使用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在滚动条中正常工作几乎是不可能的。无论如何,我会将你的标记标记为正确的。迄今为止我见过的最佳答案。谢谢。 –