【发布时间】:2015-10-13 15:46:34
【问题描述】:
我设法找到了一个函数,它给我 NE 角和 SW 角坐标,给定一个 latLng 和一个半径。
/**
* Get NE & SW coordinates around a point
*
* @param $lat float latitude of origin pt
* @param $lng float longitude of origin pt
* @param $distance int radius in km
*
*/
function getBoundsCoords($latitude, $longitude, $distance) {
$radius = 6378.1;
$neLat = rad2deg(asin(sin(deg2rad($latitude)) * cos($distance / $radius) + cos(deg2rad($latitude)) * sin($distance / $radius) * cos(deg2rad(0))));
$swLat = rad2deg(asin(sin(deg2rad($latitude)) * cos($distance / $radius) + cos(deg2rad($latitude)) * sin($distance / $radius) * cos(deg2rad(180))));
$neLng = rad2deg(deg2rad($longitude) + atan2(sin(deg2rad(90)) * sin($distance / $radius) * cos(deg2rad($latitude)), cos($distance / $radius) - sin(deg2rad($latitude)) * sin(deg2rad($neLat))));
$swLng = rad2deg(deg2rad($longitude) + atan2(sin(deg2rad(270)) * sin($distance / $radius) * cos(deg2rad($latitude)), cos($distance / $radius) - sin(deg2rad($latitude)) * sin(deg2rad($neLat))));
return array(
'ne' => array(
'lat' => $neLat,
'lng' => $neLng
),
'sw' => array(
'lat' => $swLat,
'lng' => $swLng
)
);
}
我还设法找到了对面函数的一部分,它给我返回了中心点坐标(很容易),但我无法找到返回的半径:
function getCoordsFromBounds($coordsNeSw) {
return array(
'lat' => ($coordsNeSw['ne']['lat'] + $coordsNeSw['sw']['lat']) / 2,
'lng' => ($coordsNeSw['ne']['lng'] + $coordsNeSw['sw']['lng']) / 2,
'radius' => "??????"
);
}
我怀疑我应该做与 getBoundsCoords() 函数相反的操作,但我对 sin/cos/deg/rad 不太满意...
【问题讨论】:
-
当您说“来自 NE SW 区域”时,您的意思是您获得了平方英里,或者您获得了 NE 和 SW 坐标并且您需要基于此的半径?
-
NE 和 SW 坐标已给出,我正在根据该坐标寻找半径
标签: php geometry coordinates