diff --git a/models/Point.php b/models/Point.php index b75e5b9..81ce1ae 100644 --- a/models/Point.php +++ b/models/Point.php @@ -49,10 +49,14 @@ class Point extends Model public function getClosestPoints($pointId) { + $degrees = 1; + $point = Point::model()->getByPK($pointId); $lat = floatval($point->lat); $lng = floatval($point->lng); + $delta = (1+abs(SIN($lat/100)*SIN($lat/100)*5))*$degrees; + $query = ' SELECT *, ( (POW(`lat`-:lat,2)+POW(`lng`-:lng,2)) @@ -71,7 +75,7 @@ class Point extends Model LIMIT 6;'; $res = App::DB()->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY)); - $res->execute(array(':lat' => $lat, ':lng' => $lng, ':minLat' => $lat - 1, ':minLng' => $lng - 1, ':maxLat' => $lat + 1, ':maxLng' => $lng + 1)); + $res->execute(array(':lat' => $lat, ':lng' => $lng, ':minLat' => $lat - $degrees, ':minLng' => $lng - $delta, ':maxLat' => $lat + $degrees, ':maxLng' => $lng + $delta)); $ready = array(); $calledClass = get_called_class();