问题
I'm trying to use a StageWebView
to display a Google Maps map generated using the Javascript API. Is there a reason why it won't render on iOS? It works on Android and in the AIR simulator, but not on iOS devices. I can view the HTML generated in Safari, too, which makes it even odder.
Example HTML (I am dynamically generating this in-app, not that it matters):
<!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>
I'm loading it using StageWebView.loadString( html, "text/html" );
. Any idea why it doesn't render? Loading URLs seems to work (so I will try saving the HTML to disk and loading that instead, next) fine, just not loadString.
Tested on both iOS 6 and iOS 7 and with AIR 3.8 and 3.9
EDIT:
As a follow up, saving the HTML file to disk and then loading that via StageWebView.loadURL()
works just fine. Still curious why loading it via loadString()
doesn't work, though.
回答1:
I think that has go to do with iOS javascript sandboxing and the way the StageWebView API works. A while ago i tried to do something similar with the twitter service to skip the pin auth, but it seems that ios won't let you execute javascript from your app.
You can try using a native webview extension to remedy this. stagewebviewbridge has a loadString method that should work with javascript.
You could use a native extension to do your map browsing. if your app is ios exclusive, you can check out: air-maps-ane or you can use the MapQuest API. i have used in a android/ios app and works very well.
回答2:
Try to remove <!DOCTYPE HTML>
tag
I have the same problem before, after remove <!DOCTYPE HTML>
the page rendered correctly
来源:https://stackoverflow.com/questions/19144441/using-stagewebview-loadstring-to-display-google-maps-on-air-for-ios