我有一些坐标,我想检查这些坐标是否恰好在谷歌地图范围内(东北和西南)。
示例:
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; }