我看到这么多功能,但它只适用于
MySQL或Postgresql.我想要
PHP的等效逻辑.我在做一些比较,
就像我有创建时正在生成的这些数据.
就像我有创建时正在生成的这些数据.
Lat: 56.130366 Long: -106.34677099999
之后,我想检查这个坐标是否落在另一个坐标的半径之内,然后返回true,否则为false.
Lat: 57.223366 Long: -106.34675644699 radius: 100000 ( meters )
提前致谢!
谢谢您的帮助.下面是一个示例函数,它需要两组经度和纬度坐标,并返回两者之间的距离.
function 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;
return $d;
}
$distance = getdistance( 56.130366,-106.34677099999,57.223366,-106.34675644699 );
if( $distance < 100 ) {
echo "Within 100 kilometer radius";
} else {
echo "Outside 100 kilometer radius";
}