Skip to content

Instantly share code, notes, and snippets.

@sorenmalling
Created September 7, 2017 06:24
Show Gist options
  • Select an option

  • Save sorenmalling/203bb261b6c6e2ec345ed92af7dba6ce to your computer and use it in GitHub Desktop.

Select an option

Save sorenmalling/203bb261b6c6e2ec345ed92af7dba6ce to your computer and use it in GitHub Desktop.
<?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