I need to parse an googleReverseGeocoding XML response. The following code is a response sample.
<GeocodeResponse>
<status>OK</status>
<result>...</result>
<result>
<type>sublocality</type>
<type>political</type>
<formatted_address>Oeiras, Portugal</formatted_address>
<address_component>
<long_name>Oeiras</long_name>
<short_name>Oeiras</short_name>
<type>sublocality</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Lisboa</long_name>
<short_name>Lisboa</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<result>...</result>
<result>...</result>
</GeocodeResponse>
I need to find the “long_name” tag with the value “Lisboa”, which appears when the type tag is administrative_area_level_1.
I tried the following but it doesn’t work:
result.city = geocodeResponse.result.find{it.address_component.type == "administrative_area_level_1"}.address_component.find{it.type == "administrative_area_level_1"}.long_name as String
A little help would be great.
Thanks in advance.
Try something like this: