I have a field called distance that I need to populate with the distance between two postcodes. I have created 4 fields that hold the latitude and longitude co-ordinates of the postcode. These are hlat hlon wlat and wlon - I have placed the following code in the custom section of the field properties box
{
$pi80 = M_PI / 180;
$data["hlat"] *= $pi80;
$data["hlon"] *= $pi80;
$data["wlat"] *= $pi80;
$data["wlon"] *= $pi80;
$value =
$r = 6372.797; // mean radius of Earth in km
$dlat = $data["wlat"] - $data["hlat"];
$dlng = $data["wlon"] - $data["hlon"];
$a = SIN($dlat / 2) * SIN($dlat / 2) + COS($data["hlat"]) * COS($data["wlat"]) * SIN($dlng / 2) * SIN($dlng / 2);
$c = 2 * ATAN2(SQRT($a), SQRT(1 - $a));
$km = $r * $c;
RETURN ($miles ? ($km * 0.621371192) : $km);
I'm getting nothing - any help would be appreciated.
Cheers