Created
October 22, 2010 09:11
-
-
Save FutureMedia/640209 to your computer and use it in GitHub Desktop.
Geolocation search (http://podscms.org/qna/questions/1525/using-a-mysql-select-as-alias)
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 | |
/* | |
I've got a Pod called 'places'. I've geocoded the addresses in 'places', and stored the coordinates in columns 'lat' and 'long'. I'm also doing a GeoIP lookup on my users, and storing their location in $usr_lat and $usr_long. (I promise to share how I'm doing all this when I get the bugs worked out). | |
Here's my code: | |
*/ | |
$Record = new Pod('places'); | |
$params = array( | |
'select' => "t.*, ( 3959 * acos( cos( radians($lat) ) * cos( radians( t.lat ) ) | |
* cos( radians( t.long ) - radians($long) ) + sin( radians($lat) ) | |
* sin( radians( t.lat ) ) ) ) AS DISTANCE", | |
'orderby' => "DISTANCE ASC", | |
'limit'=>25, | |
'where'=>'t.publish AND t.lat IS NOT NULL' | |
); | |
$Record->findRecords($params); | |
while ($Record->fetchRecord()){ | |
echo $Record->get_field('name') . " is " . $Record->get_field('DISTANCE'); . " miles away\n"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment