I have users that input data that is sometimes is not correct. For instance they might misspell their city or they might write 'St John' instead of 'St. John'. I would rather not dirty up my database so I would like to check with Google to see if what the user inputted was correct.
How do I extract the city 'Mountain View' from the below code? I think I am getting close but I am not good at parsing XML.
How do I extract the city 'Mountain View' from the below code? I think I am getting close but I am not good at parsing XML.
Code:
<cfhttp
url="[URL unfurl="true"]http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true"[/URL]
method="GET" resolveurl="No" timeout="30" throwonerror="yes">
</cfhttp>
<cfset xmlDoc = XmlParse(CFHTTP.FileContent)>
<cfloop
index="address_component"
from="1"
to="#ArrayLen( xmlDoc.GeocodeResponse.XmlChildren )#"
step="1">
<!--- Get a short hand for the current rentalad node. --->
<cfset xmladdress_component = xmlDoc.GeocodeResponse[ "address_component" ][ address_component ] />
<!--- Get the contactinfo children. --->
<cfset xmlLong_name = xmladdress_component[ "long_name" ] />
<cfoutput>
#xmlAddress_component.long_name.xmltext#<br />
</cfoutput>
</cfloop>
<CFDUMP var="#xmlDoc#">