Click to See Complete Forum and Search --> : Distance Finder


c p c
12-29-2003, 09:27 AM
Hi,

Does anyone have a script that I can use to generate the distance in miles between two postcodes?

I have the coordiantes and data in a DB and can't seem to find or figure out the script/formula in PHP to get the distances.

I basically want to input a postcode into a form and then have a list of results in order of distance from the user. If anyone has one lying around it would be very useful.

thanks

diamonds
12-29-2003, 12:36 PM
remember
a^2 + b^2 = c^2
imagine the lines as a triangle.

diamonds
12-29-2003, 12:53 PM
use the image attached eith this description.

find the lenth of line D, square it.
find the lenth of line E, square it.
add the values.
square-root the result.
the awnser is the distance between points A and B.

c p c
12-30-2003, 04:24 AM
OK thanks, I'll give that a go.

diamonds
12-30-2003, 09:08 AM
here is a full function:


function find_d($q1_x,$q1_y,$q2_x,$q2_y){
$d = sqrt(pow(abs($q1_x - q2_x), 2)+pow(abs($q1_y - q2_y), 2));
return $d;
}

it dosnt matter where you place the coordinates, they are revirseable.
the "x" and "y" though, must be placed in the right sopts
(x first, y last, same for next set)