Google Maps API Lat/Lon Lookup

This form and code do a Google Maps API lookup and parses the resulting XML to extract the formatted address and latitude and longitude of the address.

Address to Geocode
Latitude: 38.8976964
Longitude: -77.0365191

Negative Longitude = WEST
Negative Latitude = SOUTH


---------- COLDFUSION CODE TO IMPLEMENT GOOGLE MAPS API XML -------------------
<cfparam name="form.address" default="1600 Pennsylvania Avenue Northwest, Washington, DC 20500-0003 USA" />

<cfhttp url="http://maps.google.com/maps/api/geocode/xml" method="GET">
 <cfhttpparam type="FORMFIELD" name="address" value="#form.address#" />
 <cfhttpparam type="FORMFIELD" name="sensor" value="false" />
</cfhttp> 

<cfset myXMLDoc = XMLParse(cfhttp.fileContent) />


<form action="latlonlookup.cfm" method="post">

<cfoutput>
Address: <input type="Text" name="address" value="#myXMLDoc.GeocodeResponse.result.formatted_address.XmlText#" style="width:450px;font-size:0.8em;" onclick="this.value='';" /> <input type="Submit" value="Go" />

</form>
Latitude: #myXMLDoc.GeocodeResponse.result.geometry.location.lat.XmlText#<br />
Longitude: #myXMLDoc.GeocodeResponse.result.geometry.location.lng.XmlText#
</cfoutput>
614 page views

Home  |   Email and Web Hosting  |   Lat/Lon Lookup  |   Link Builder  |   Math  |  
Image Resizing Calculator  |   Naked Option Margin Calculator
Copyright © 2010, All rights reserved.
Maintained by Tom Nunamaker