Geocoding UK postcodes with PostcodeAnywhere

·
PostcodeAnywhere has a geocoding web service for UK postcodes. If you register for a free trial account, you get 10 free lookups. After that the cheapest package is 300 lookups for $25 (or 1000 lookups for £50), with a limit of 100 lookups per day. Here's how to run a query in PHP5:

$account_code = 'YOUR_ACCOUNT_CODE'; // http://www.postcodeanywhere.co.uk/account/
$licence_key = 'YOUR_LICENCE_KEY'; // http://www.postcodeanywhere.co.uk/account/licensemanager/
$postcode = 'YOUR_POSTCODE';
$url = 'http://services.postcodeanywhere.co.uk/xml.aspx?action=geocode&account_code=' . urlencode($account_code) .  '&license_code=' . urlencode($licence_key) . '&postcode=' . urlencode($postcode);
$xml = simplexml_load_string($url);
$item = array_shift($xml->xpath('//Data/Item'));
$latitude = $item['wgs84_latitude'];
$longitude = $item['wgs84_longitude'];
print $postcode . ': ' . $latitude . ',' . $longitude . "\n";