Created
June 12, 2014 11:27
-
-
Save lozcalver/f43ceaab15011f717740 to your computer and use it in GitHub Desktop.
This file contains 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 | |
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