Created
September 7, 2017 06:24
-
-
Save sorenmalling/203bb261b6c6e2ec345ed92af7dba6ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| public function findByPlaceAndRadius(Place $place, $radius, $limit = 15) { | |
| $latitude = $place->getLatitude(); | |
| $longitude = $place->getLongitude(); | |
| $angleRadius = $radius / 111; | |
| $min_lat = $latitude - $angleRadius; | |
| $max_lat = $latitude + $angleRadius; | |
| $min_lon = $longitude - $angleRadius; | |
| $max_lon = $longitude + $angleRadius; | |
| $query = $this->createQuery(); | |
| $constraints[] = $query->logicalAnd( | |
| $query->lessThan('latitude', $max_lat), | |
| $query->greaterThan('latitude', $min_lat), | |
| $query->lessThan('longitude', $max_lon), | |
| $query->greaterThan('longitude', $min_lon) | |
| ); | |
| $constraints[] = $query->logicalNot( | |
| $query->equals('uid', $place) | |
| ); | |
| $query->matching($query->logicalAnd($constraints)); | |
| $query->setLimit($limit); | |
| return $query->execute(); | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment