Ejemplo n.º 1
0
 private function getNearbyUsers($latitude, $longitude, $distance, $userId)
 {
     $locations = Location::where('updated_at', '>', date("Y-m-d H:i:s", time() - self::LAST_ACTIVE_THRESHOLD_IN_SECONDS))->with("user", "user.contact", "user.bodyInformation")->get();
     if ($locations->isEmpty()) {
         return Response::json(array("status" => "ok", "users" => array(), "msg" => "No users recently active in your area."));
     }
     $users = array();
     foreach ($locations as $location) {
         if ($location->user_id == $userId) {
             continue;
         }
         $distanceFromUser = Distances::distanceInMiles($latitude, $longitude, $location->latitude, $location->longitude);
         if ($distanceFromUser <= $distance) {
             $location['distance'] = $distanceFromUser;
             array_push($users, $location);
         }
     }
     return Response::json(array("status" => "ok", "users" => $users, "msg" => "This is all the active users near you right now!"));
 }
Ejemplo n.º 2
0
 public static function distanceInKilometers($lat1, $lon1, $lat2, $lon2)
 {
     return Distances::distance($lat1, $lon1, $lat2, $lon2) * 1.609344;
 }
Ejemplo n.º 3
0
 public function testCalculate()
 {
     $this->assertEquals(10548.050763187448, Distances::calculate(2, 100, 50, 200, 'K'));
 }