static public $DEF_PI = 3.14159265359; // PI
static public $DEF_2PI= 6.28318530712; // 2*PI
static public $DEF_PI180= 0.01745329252; // PI/180.0
static public $DEF_R =6370693.5; // radius of earth
/**
* 适用于近距离测直线距离
*/
public static function GetShortDistance($lon1, $lat1, $lon2, $lat2)
{
// 角度转换为弧度
$ew1 = $lon1 * self::$DEF_PI180;
$ns1 = $lat1 * self::$DEF_PI180;
$ew2 = $lon2 * self::$DEF_PI180;
$ns2 = $lat2 * self::$DEF_PI180;
// 经度差
$dew = $ew1 - $ew2;
// 若跨东经和西经180 度,进行调整
if ($dew > self::$DEF_PI)
$dew = self::$DEF_2PI - $dew;
else if ($dew < -self::$DEF_PI)
$dew = self::$DEF_2PI + $dew;
$dx = self::$DEF_R * cos($ns1) * $dew; // 东西方向长度(在纬度圈上的投影长度)
$dy = self::$DEF_R * ($ns1 - $ns2); // 南北方向长度(在经度圈上的投影长度)
// 勾股定理求斜边长
$distance = sqrt($dx * $dx + $dy * $dy);
return $distance;
}