2012-03-06 42 views
1

我試圖在Flex Mobile應用程序內加載一個帶有Google Maps JavaScript API的StageWebView,作爲Google Maps API for Flash的解決方法,不適用於iOS。我正在使用stageWebView.loadString()方法。以下是正在加載的HTML.Javascript的相關部分。Google Maps JS API v3不會在Flex Mobile內部加載StageWebView

我的問題是,當我在瀏覽器(IE,Chrome和Safari)以及Flash Builder iPhone/iPad模擬器中查看時,所有內容都能正常工作。在實際的設備上,map永遠不會加載,通過一些try..catch語句,我能夠識別出我得到的「TypeError:'undefined'不是構造函數」錯誤,這些錯誤是由我列在內部的每一行引發的下面的初始化函數。

有關可能出錯的任何想法?

<!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包含的對象,驚訝地發現,不同對象出現在瀏覽器中,與MapPolylineMarkerGeocoder,以及其他子對象的主機,由iOS設備呈現的版本看起來像這樣:

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發揮作用?

+0

好的問題是Google不再支持Flash/Flex Maps API,並告訴每個人都使用JS Maps API。 – 2012-03-07 12:39:49

回答

1

確實懷疑外部腳本是否被加載。我的猜測是,由於連接或許可權限,你無法下載導致錯誤的外部腳本。

嘗試測試,看看谷歌的變量在使用它

if (typeof google !== 'undefined') { 
    // Use google 
} else { 
    // Warn the user they may not be connected to the internet? 
} 

如果你認爲你正確地擁有一切設置,嘗試把你的腳本上的外部位置和加載頁面從extenal位置即之前定義而不是使用stageWebView.loadString()嘗試stageWebView.loadURL()只是爲了測試。如果不加載,您可能會拒絕您的應用程序Internet訪問。我不知道這是怎樣適用於iOS,但建議是,你是問關於這個問題,並且當您嘗試訪問該資源 - 通過表示:

http://help.adobe.com/en_US/flex/mobileapps/WSa8161994b114d624-33657d5912b7ab2d73b-7fe2.html

這可能會或可能不會解決您的問題,但我希望這個答案對於使用.loadString()時被抓到的人有幫助。當您已經看到網頁內容時,很容易忘記檢查您是否確實能夠訪問互聯網,而網頁內容實際上是從一個字符串中加載的。

+0

感謝您的及時迴應!我在'initialize()'的開頭添加了一個提醒,告訴我google和google.maps的類型,並且他們都返回了'object'。我知道Flex應用程序可以訪問Internet - 我通過應用程序中的'stageWebView.loadURL()'方法加載StageWebView。 我無法從外部位置加載文件,我選擇使用'StageWebView.loadString()'的原因是因爲我需要在運行時通過Flex應用程序更改它的內容。 – FlexMobileAmateur 2012-03-07 13:35:40