我有一些座標,我想檢查這些座標是否恰好在Google地圖範圍內(東北和西南)。
範例:
Available Lat: 40.712776 Available Long: -74.005974
我想知道上面的座標是否在下面的邊界內:
> bounds_north_east[lat] 28.63713261089665 > bounds_north_east[lng] 77.22579752272338 > bounds_south_west[lat] 28.619767323553265 > bounds_south_west[lng] 77.18275343245239
我想僅使用 PHP 腳本來實現此目的。
P粉1908832252024-04-05 13:43:10
這對我有幫助。它傳回 true 或 false。
function inBounds($pointLat, $pointLong, $boundsNElat, $boundsNElong, $boundsSWlat, $boundsSWlong) { $eastBound = $pointLong < $boundsNElong; $westBound = $pointLong > $boundsSWlong; if ($boundsNElong < $boundsSWlong) { $inLong = $eastBound || $westBound; } else { $inLong = $eastBound && $westBound; } $inLat = $pointLat > $boundsSWlat && $pointLat < $boundsNElat; return $inLat && $inLong; }