0
AS3代碼寫得很差,我需要從Google Maps Api檢索XML數據並從中檢索節點/字符串。沒有發生。我需要使用XML Data作爲變量值,然後將它的子節點和該子節點放入數組中(有點像我的推特XML數據)。這是我的輸出:來自Geocode Api的XML無法通過AS3轉換爲XML
RT @StonesGotStyle: Feeling terrible, darn you flu! This may be the only way to make me feel better! http://t.co/RJLEog6c8c So awesome! @OM…
Majulah Singapura
have the worst heyfever, and coming down with a flu whilst having guests round and I need to revise is the worst scenario **
London
2
TypeError: Error #1034: Type Coercion failed: cannot convert "<?xml version="1.0" encoding="UTF-8"?>
<GeocodeResponse>
<status>OK</status>
<result>
<type>country</type>
<type>political</type>
<formatted_address>United Kingdom</formatted_address>
<address_component>
<long_name>United Kingdom</long_name>
<short_name>GB</short_name>
<type>country</type>
<type>political</type>
</address_component>
<geometry>
<location>
<lat>55.3780510</lat>
<lng>-3.4359730</lng>
</location>
<location_type>APPROXIMATE</location_type>
<viewport>
<southwest>
<lat>49.8669688</lat>
<lng>-8.6493572</lng>
</southwest>
<northeast>
<lat>60.8565530</lat>
<lng>1.7627096</lng>
</northeast>
</viewport>
<bounds>
<southwest>
<lat>34.5640831</lat>
<lng>-8.6493572</lng>
</southwest>
<northeast>
<lat>60.9113448</lat>
<lng>33.9165549</lng>
</northeast>
</bounds>
</geometry>
</result>
</GeocodeResponse>
" to XML.
at app::main/locate()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
而且我的代碼:
package app
{
import flash.xml.XMLDocument;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.display.MovieClip;
public class main extends MovieClip
{
public var geoReq:URLRequest = new URLRequest;
public var geoLoader:URLLoader = new URLLoader();
public var geoXml:XML = new XML();
public var geoLocList:XMLList = new XMLList();
public var geoLoc:Array = new Array();
public function main():void
{
geoLoader.addEventListener(Event.COMPLETE, locate);
var urlReq:URLRequest = new URLRequest("http://search.twitter.com/search.atom?q=flu&rpp=3&lang=en&geocode=55.378051,-3.435973,605mi");
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, getTweets);
loader.load(urlReq);
}
function getTweets(e:Event):void
{
loadGeo("UK");
if (e.target.data)
{
var tweets = new Array(); var times = new Array();
var twitterXML:XML = new XML(e.target.data);
var tweetList:XMLList = twitterXML.children();
var tweetItem:String;
var placeItem:String;
var tweet:Array = new Array();
for (var i:int = 0; i < tweetList.length(); i++)
{
tweetItem = tweetList[i].*::title;
placeItem = tweetList[i].*::location;
if(tweetItem && placeItem != "")
{
tweet = [tweetItem, placeItem];
tweets.push(tweet);
trace(tweets[tweets.length - 1][0]);
trace(tweets[tweets.length - 1][1]);
}
}
trace(tweets.length);
}
}
function loadGeo(loc:String):void
{
geoReq = new URLRequest("https://maps.googleapis.com/maps/api/geocode/xml?address=" + loc + "&sensor=false");
geoLoader.load(geoReq);
}
function locate(e:Event):void
{
geoXml = e.target.data;
//geoLocList = geoXml.children();
//geoLoc = [geoLocList[0].*::lat, geoLocList[0].*::lng];
trace("located");
trace(e.target.data);
//trace(geoXml);
trace("located");
}
}
}
請幫幫忙,先謝謝了,凱爾。