lat = $lat; $this->lon = $lon; $this->radius = $radius; } /** * @return array */ public function getCenter() { return [ 'lat' => $this->lat, 'lon' => $this->lon ]; } /** * @return array */ public function getLatitudes() { $latDeg = rad2deg($this->radius / self::EARTH_RADIUS ); return [ 'min' => $this->lat - $latDeg, 'max' => $this->lat + $latDeg, ]; } /** * @return array */ public function getLongitudes() { $lonDeg = rad2deg($this->radius / self::EARTH_RADIUS / cos( deg2rad( $this->lat ) ) ); return [ 'min' => $this->lon - $lonDeg, 'max' => $this->lon + $lonDeg, ]; } /** * Returns true if the value is between the min and max of the coordinates * * @param float $value * @param array $coords * * @return bool */ protected function filter( float $value, array $coords ) { return $value >= $coords['min'] && $value <= $coords['max']; } /** * Checks if the $coordinate is in the boundary box * * @param float $lat * @param float $lon * * @return bool */ public function check( float $lat, float $lon ): bool { $isLat = $this->filter( $lat, $this->getLatitudes() ); $islon = $this->filter( $lon, $this->getLongitudes() ); return $isLat && $islon; } }