HTTPService 将地理编码结果返回到 DataGrid 的问题
我正在创建一个 Flex3 应用程序,以从 Google 地理编码 API 返回一些结果。
我使用 TourDeFlex 中的 HTTPService 事件示例作为参考指南模仿。
目前,我已对 Google 的响应进行了硬编码以使用此 XML 响应: 地图.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false
网络监视器表明我从 XML 中获得了有效响应,但我想我没有正确引用它来填充我的 DataGrid?
我已在此处截屏了该问题。
这是我的代码的精简版本:
private function resultHandler(event:ResultEvent):void
{
results = event.result.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>
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.result.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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看了一下xml。第一次出现的 type 可能位于顶层,但从那时起 type 就成为 address_component 的元素。
也许尝试 address_component.type 作为 DataGridColumn 的数据字段?或者将 dataprovider 设置为 results.address_component?
编辑更新
因为它读取XML,所以可以在
标签内设置resultFormat="e4x"
,并有一个XMLListCollection等待结果:在调试模式下,在 XC 上设置监视以确保其已填充
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:In debug mode, set a watch on XC to make sure its being populated