phil has a blog - UK Postcode to coordinates function with Google APIs

UK Postcode to coordinates function with Google APIs

http://code.google.com/apis/maps/signup.html

<?php $key = ''; ?>
<script src="http://maps.google.com/maps?file=api&v=2&key=<?=$key?>" type="text/javascript"></script>
<script src="http://www.google.com/uds/api?file=uds.js&v=1.0&key=<?=$key?>"type="text/javascript"></script>
<script type="text/javascript">

var localSearch = new GlocalSearch();

function findCoordinates(postcode, callbackFunction) {

	if (postcode == '')
		return;
  
	localSearch.setSearchCompleteCallback(null,
	function() {
		if (localSearch.results[0]) {
			var resultLat = localSearch.results[0].lat;
			var resultLng = localSearch.results[0].lng;
			callbackFunction(resultLat,resultLng);
		}
		else
		{
			alert("Postcode not found!");
		}
	});  
    
	localSearch.execute(postcode + ", UK");
}
		
function updateInputs(lat, lon)
{
	document.getElementById('lat').value = lat;
	document.getElementById('lon').value = lon;
}

</script>	
	
<p><label>UK Postcode: <br /><input class="text" type="text" id="postcode" name="postcode" size="7" value="" /></label> 
<input type="button" onclick="findCoordinates(document.getElementById('postcode').value, updateInputs); return false;" value="Find Latitude and Longitude coordinates" /></p>
<p><label>Lat: <input type="text" id="lat" name="lat" size="10" value="" /></label> 
<label>Lon: <input type="text" id="lon" name="lon" size="10" value="" /></label></p>