I am creating a Flex3 app to return some results from the Google Geocoding API.
I am using the HTTPService Events sample from TourDeFlex as a reference guide to mimic.
For now, I have hardcoded the response from Google to use this XML response: maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false
Network Monitor suggests that I am getting a valid response from the XML, but I imagine I have not referenced it correctly for populating my DataGrid?
I have screencasted the issue here.
Here is a stripped down version of my code:
private function resultHandler(event:ResultEvent):void
{
results = event.re开发者_开发问答sult.GeocodeResponse.result;
}
private function faultHandler(event:FaultEvent):void
{
Alert.show(event.fault.faultDetail, "Error");
}
]]>
</mx:Script>
<mx:HTTPService id="srv"
url="http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false"
result="resultHandler(event)"
fault="faultHandler(event)"/>
<mx:TitleWindow title="Find" showCloseButton="true" close="closeMe();"
styleName="formPanel" horizontalScrollPolicy="off" verticalScrollPolicy="off"
width="400" height="200">
<mx:DataGrid dataProvider="{results}" width="100%" height="100%">
<mx:columns>
<mx:DataGridColumn dataField="type" headerText="Address"/>
</mx:columns>
</mx:DataGrid>
<mx:Button label="Go" height="20" styleName="buttonGo" click="srv.send()"/>
</mx:TitleWindow>
Had a look at the xml. It could be that the first occurance of type is at a top level, but from then on type is an element of address_component.
Maybe try address_component.type as the datafield of the DataGridColumn? Or set the dataprovider to results.address_component?
Edit Update
Because its reading XML, maybe set resultFormat="e4x"
inside the <HttpService ..>
tag, and have an XMLListCollection awaiting the result:
<mx:XMLListCollection id="xc" source="{srv.lastResult.result}"/>
<mx:DataGrid id="dg" dataProvider="{xc}">
In debug mode, set a watch on XC to make sure its being populated
精彩评论