11-06-2007 20:51:08
A PHP sample of triangulation which allows you to calculate the distance between postcodes. From http://www.sloomedia.com/php_postcode_script.php
A script and file to find distance between postcodes.
----------------
<?php
function calc_postcode_seperation($pcodeA,$pcodeB)
{
// PCODE A
$result=mysql_query("SELECT * FROM postcodes WHERE Pcode='$pcodeA' LIMIT 1");
$row=mysql_fetch_array($result);
$gridn[0]=$row[Grid_N];
$gride[0]=$row[Grid_E];
// PCODE B
$result=mysql_query("SELECT * FROM postcodes WHERE Pcode='$pcodeB' LIMIT 1");
$row=mysql_fetch_array($result);
$gridn[1]=$row[Grid_N];
$gride[1]=$row[Grid_E];
// TAKE GRID REFS FROM EACH OTHER.
$distance_n=$gridn[0]-$gridn[1];
$distance_e=$gride[0]-$gride[1];
// CALCULATE THE DISTANCE BETWEEN THE TWO POINTS
$hypot=sqrt(($distance_n*$distance_n)+($distance_e*$distance_e));
$text.='Distance between '.$pcodeA.' and '.$pcodeB.' is: '.round($hypot/1000,2).'kms';
return $text;
}
echo calc_postcode_seperation('LE7','BD1');
?>

Enter you login details below to sign in to the site.
If you do not have a login you will need to register.