Maison  >  Questions et réponses  >  le corps du texte

Comment vérifier si les coordonnées sont à l'intérieur des limites de l'objet en PHP ?

J'ai quelques coordonnées et je souhaite vérifier si ces coordonnées se situent exactement dans la plage Google Maps (nord-est et sud-ouest).

Exemple :

Available Lat: 40.712776
Available Long: -74.005974

Je veux savoir si les coordonnées ci-dessus se trouvent dans les limites ci-dessous :

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

Je souhaite y parvenir en utilisant uniquement un script PHP.

P粉101708623P粉101708623170 Il y a quelques jours1394

répondre à tous(1)je répondrai

  • P粉190883225

    P粉1908832252024-04-05 13:43:10

    Cela m'aide. Il renvoie vrai ou faux.

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

    répondre
    0
  • Annulerrépondre