1// first-cut bounding box (in degrees)
2$maxLat = $lat + rad2deg($rad/$R);
3$minLat = $lat - rad2deg($rad/$R);
4$maxLon = $lon + rad2deg(asin($rad/$R) / cos(deg2rad($lat)));
5$minLon = $lon - rad2deg(asin($rad/$R) / cos(deg2rad($lat)));
6
7$sql = "Select Id, Postcode, Lat, Lon
8 From MyTable
9 Where Lat Between :minLat And :maxLat
10 And Lon Between :minLon And :maxLon";
11
12
13$r = $db->prepare("SELECT * FROM location WHERE laltutide Between :minlat AND :maxlat
14 AND longetude between :minlon AND :maxlon");
15
16$r->execute();
17
18$r = $r->fetchAll(PDO::FETCH_OBJ);
19
20