Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

i am designing a recruitment database, and i need it to perform several tasks that all involve integrating a way of calculating distance:

1) calculate the distance the candidate lives from the client?

2) calculate the clients within a radius of the candidates available for work on any given day?

3) calculating the number of candidates with the correct qualifications for the vacancy within a radius of the client.

as you can see i need to calculate the distance in 2 main ways 1) radius 2) as the crow flies, i would prefer exact distance but the first will do. i know that i can integrate Google maps or some other web based mapping but i want the system to be stand alone so it can function without an internet connection. the system will have a HTML5 front end and the Back end is in Mysql and PHP.

thank you biagio

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
328 views
Welcome To Ask or Share your Answers For Others

1 Answer

The distance between 2 points could be calculated with the following formula :

6371*acos(cos(LatitudeA)*cos(LatitudeB)*cos(longitudeB-longitudeA)+sin(LatitudeA)*sin(latitudeB))

Of course it's a "crow flies" approximation in Km.

Wich can be translated to php by :

$longA     = 2.3458*(M_PI/180); // M_PI is a php constant
$latA     = 48.8608*(M_PI/180);
$longB     = 5.0356*(M_PI/180);
$latB     = 47.3225*(M_PI/180);

$subBA       = bcsub ($longB, $longA, 20);
$cosLatA     = cos($latA);
$cosLatB     = cos($latB);
$sinLatA     = sin($latA);
$sinLatB     = sin($latB);

$distance = 6371*acos($cosLatA*$cosLatB*cos($subBA)+$sinLatA*$sinLatB);
echo $distance ;

With that you could compute the distance between two points (people) and of course determine if a point is in a radius of an other.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...