Skip to content

Instantly share code, notes, and snippets.

@kinglozzer
Created June 12, 2014 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kinglozzer/f43ceaab15011f717740 to your computer and use it in GitHub Desktop.
Save kinglozzer/f43ceaab15011f717740 to your computer and use it in GitHub Desktop.
<?php
class ParkListing extends Location {
/**
* @param GeocodedLocation $location
* @return DataList
*/
public static function get_by_geo(GeocodedLocation $location) {
$query = new SQLQuery();
$query->setFrom('Location');
$query->addLeftJoin('ParkListing', 'Location.ID = ParkListing.ID');
$query->selectField(
'(((acos(sin((' . $location->Lat . ' *pi()/180))*sin((`GMapLat`*pi()/180))+cos(('
. $location->Lat . '*pi()/180))*cos((`GMapLat`*pi()/180))*cos(((' . $location->Lon
. '-`GMapLon`)*pi()/180))))*180/pi())*60*1.1515) as Distance'
);
$query->setHaving('Distance < 50');
$query->setOrderBy('Distance', 'asc');
$array = $query->execute();
$results = array();
foreach($array as $row) {
$results[] = self::create($row);
}
return new ArrayList($results);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment