计算距离 [英] calculate distance

查看:100
本文介绍了计算距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个招聘数据库,我需要它来执行几项所有涉及整合计算距离的方法的任务:

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

1)计算候选人的距离来自客户的生活?

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

2)计算任何一天可供工作的候选人半径范围内的客户?

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

3)计算在客户半径范围内具有正确空缺资格的候选人数。

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

您可以看到我需要计算距离主要有两种方式:1)半径2)随着乌鸦的飞行,我宁愿选择确切的距离,但第一种方法也是如此。
我知道我可以集成谷歌地图或其他一些基于网络的地图,但我希望系统能够独立,这样它就可以在没有互联网连接的情况下运行。
系统将有一个HTML5前端,后端是在Mysql和PHP中。

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.

谢谢你biagio

推荐答案

可以使用以下公式计算2点之间的距离:

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.

可以通过以下方式翻译成php:

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.

这篇关于计算距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆