Heim  >  Fragen und Antworten  >  Hauptteil

Wie überprüfe ich, ob sich Koordinaten in PHP innerhalb der Objektgrenzen befinden?

Ich habe einige Koordinaten und möchte überprüfen, ob diese Koordinaten genau im Google Maps-Bereich (Nordosten und Südwesten) liegen.

Beispiel:

Available Lat: 40.712776
Available Long: -74.005974

Ich möchte wissen, ob die oben genannten Koordinaten innerhalb der unten aufgeführten Grenzen liegen:

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

Ich möchte dies nur mit PHP-Skripten erreichen.

P粉101708623P粉101708623170 Tage vor1393

Antworte allen(1)Ich werde antworten

  • P粉190883225

    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;
    }

    Antwort
    0
  • StornierenAntwort