用什么公式来计算一个小距离 [英] What formula to use to calculate a small distance

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

问题描述

我需要计算2个GPS点之间的距离。

我读过这个问题公式来计算地理邻近度但我的英语太糟糕了。



我的问题是2点最多只有1公里。
我需要最令人兴奋的公式,因为距离很短



PHP或伪代码中的一个例子会很棒

解决方案

请参阅此页面。它包含各种编程语言的大圆距离计算函数。



在PHP中:

 函数getDistance($ latitude1,$ longitude1,$ latitude2,$ longitude2 ){
$ earth_radius = 6371; //在你想要结果的单位中。

$ dLat = deg2rad($ latitude2 - $ latitude1);
$ dLon = deg2rad($ longitude2 - $ longitude1);

$ a = sin($ dLat / 2)* sin($ dLat / 2)+ cos(deg2rad($ latitude1))* cos(deg2rad($ latitude2))* sin($ dLon / 2)* sin($ dLon / 2);
$ c = 2 * asin(sqrt($ a));
$ d = $ earth_radius * $ c;

返回$ d;
}


Hy!

I need to calculate the distance between 2 GPS Points.

I read this question Formulas to Calculate Geo Proximity but i my english is too bad.

My Problem is that the 2 points are at most 1 km away. I need the most excatly formula because of the small distance

A example in PHP or pseudo code would be great

解决方案

See this page. It contains great-circle distance calculation functions for various programming languages.

In PHP:

function getDistance($latitude1, $longitude1, $latitude2, $longitude2) {  
    $earth_radius = 6371;  // In the unit you want the result in.

    $dLat = deg2rad($latitude2 - $latitude1);  
    $dLon = deg2rad($longitude2 - $longitude1);  

    $a = sin($dLat/2) * sin($dLat/2) + cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * sin($dLon/2) * sin($dLon/2);  
    $c = 2 * asin(sqrt($a));  
    $d = $earth_radius * $c;  

    return $d;  
}  

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

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