Skip to content

Instantly share code, notes, and snippets.

@FutureMedia
Created October 22, 2010 09:11
Show Gist options
  • Save FutureMedia/640209 to your computer and use it in GitHub Desktop.
Save FutureMedia/640209 to your computer and use it in GitHub Desktop.
<?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