diff --git a/config/routes.yaml b/config/routes.yaml index fe5c04a3..65713be9 100644 --- a/config/routes.yaml +++ b/config/routes.yaml @@ -7,3 +7,6 @@ home: path: / controller: App\Controller\HomeController::index +rider_locations: + path: /rider_locations + controller: App\Controller\HomeController::getRiderLocations diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index 860526eb..92a4d142 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -18,6 +18,11 @@ class HomeController extends Controller * @Menu(selected="home") */ public function index(EntityManagerInterface $em, RiderTracker $rider_tracker) + { + return $this->render('home.html.twig'); + } + + public function getRiderLocations(EntityManagerInterface $em, RiderTracker $rider_tracker) { // get all riders $riders = $em->getRepository(Rider::class)->findAll(); @@ -29,13 +34,17 @@ class HomeController extends Controller $rider_id = $rider->getID(); $coordinates = $rider_tracker->getRiderLocation($rider_id); + $long = $coordinates->getLongitude(); + $lat = $coordinates->getLatitude(); + // use rider id as key - $locations[$rider_id] = $coordinates; + $locations[$rider_id] = array($lat, $long); } - $params['riders'] = $locations; + return $this->json([ + 'riders' => $locations, + ]); - return $this->render('home.html.twig', $params); } } diff --git a/templates/home.html.twig b/templates/home.html.twig index 1641cec3..0db6800c 100644 --- a/templates/home.html.twig +++ b/templates/home.html.twig @@ -28,15 +28,13 @@