Google Maps JS API v3 不会在 Flex Mobile StageWebView 中加载 [英] Google Maps JS API v3 will not load inside Flex Mobile StageWebView
问题描述
我正在尝试在 Flex Mobile 应用程序中加载带有 Google Maps Javascript API 的 StageWebView,作为 Google Maps API for Flash 无法在 iOS 上运行的解决方法.我正在使用 stageWebView.loadString() 方法.下面是正在加载的 HTML.Javascript 的相关部分.
I am trying to load a StageWebView with the Google Maps Javascript API inside a Flex Mobile application as a workaround for the Google Maps API for Flash not working on iOS. I am using the stageWebView.loadString() method. Below is the relevent portion of HTML.Javascript being loaded.
我的问题是,当我在浏览器(IE、Chrome 和 Safari)和 Flash Builder iPhone/iPad 模拟器中查看时,一切正常.在实际设备上,地图永远不会加载,通过一些 try..catch 语句,我能够确定我收到了TypeError: 'undefined' is not a constructor"错误,我在里面列出的每一行都会抛出这些错误下面的初始化函数.
My issue is that everything works perfectly when I view this in a browser (IE, Chrome and Safari) and in the Flash Builder iPhone/iPad simulators. On the actual device the map never loads, and through some try..catch statements I was able to identify that I am getting "TypeError: 'undefined' is not a constructor" errors, which are thrown by each of the lines I listed inside the initialize function below.
对可能出错的地方有任何想法吗?
Any thoughts on what may be going wrong?
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?v=3&key=MY_KEY&sensor=true">
</script>
<script type="text/javascript">
/* a bunch of variables and functions */
function initialize() {
var myOptions = { center: new google.maps.LatLng(43.476302, -80.4816062), zoom: 12, mapTypeId: google.maps.MapTypeId.ROADMAP };
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
geocoder = new google.maps.Geocoder();
dirDisplay = new google.maps.DirectionsRenderer();
/* some other stuff */
}
if(window.addEventListener) window.addEventListener("load", initialize, true); else window.onload = initialize;
</script>
</head>
<body>
<div id="map_canvas" style="width:100%; height:100%;" ></div>
<div id="dirPanel" style="width:100%;" ></div>
</body>
</html>
我检查了 google.maps 对象包含的内容,并惊讶地发现与浏览器上显示的对象不同,Map
、Polyline
、Marker
、Geocoder
以及其他一系列子对象,iOS 设备呈现的版本如下所示:
I checked what the google.maps object contained and was surprised to find that unlike the object appearing on browsers, with Map
, Polyline
, Marker
, Geocoder
, and a host of other child objects, the version bpresented by the iOS device looks like this:
google.maps {
modules:Object,
Load:function (apiLoad) { delete google.maps.Load; apiLoad([/*lots of stuff I don't feel like copying out by hand*/], loadScriptTime); },
_gjsload_:function (name, text) { modules[name] = text; }
}
关于为什么它不同的任何想法?或者我可以做些什么来让 Maps API 正常工作?
Any thoughts as to why it is different? Or what I can do about it to get the Maps API to work?
推荐答案
通过 Alexander Farber 对 这篇文章,我决定使用MapQuest 的 Flex/Flash Mobile API,已被证明非常有效.
Through Alexander Farber's suggestion on this post, I decided to use MapQuest's Flex/Flash Mobile API, which has proven to be very effective.
这篇关于Google Maps JS API v3 不会在 Flex Mobile StageWebView 中加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!