-7

I have some co-ordinates and I want to check if these co-ordinates happens to be inside google map bounds (north-east and South-west).

Example:

Available Lat: 40.712776
Available Long: -74.005974

I want to know If above co-ordinate is within below Boundaries:

> bounds_north_east[lat]    28.63713261089665
> bounds_north_east[lng]    77.22579752272338
> bounds_south_west[lat]    28.619767323553265
> bounds_south_west[lng]    77.18275343245239

I want to achieve this using PHP script only.

1 Answers1

-2

This is what helped me. it returns true or 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;
}
  • This is not an answer, it's just a piece of code without any explanation, which it clearly needs. Why is this here? – KIKO Software May 07 '23 at 17:23
  • I found this as an answer to a SO question from 8 years ago: https://stackoverflow.com/questions/10939408/determine-if-lat-lng-in-bounds – KIKO Software May 07 '23 at 17:26