Add the rider tracker service to retrieve and display all rider locations. #270
This commit is contained in:
parent
01ffdea2d7
commit
76b291f6d7
3 changed files with 65 additions and 7 deletions
|
|
@ -87,6 +87,11 @@ services:
|
|||
$password: "%env(REDIS_CLIENT_PASSWORD)%"
|
||||
$env_flag: "dev"
|
||||
|
||||
# rider tracker service
|
||||
App\Service\RiderTracker:
|
||||
arguments:
|
||||
$redis_client: "@App\\Service\\RedisClientProvider"
|
||||
|
||||
Catalyst\APIBundle\Security\APIKeyUserProvider:
|
||||
arguments:
|
||||
$em: "@doctrine.orm.entity_manager"
|
||||
|
|
|
|||
|
|
@ -5,13 +5,37 @@ namespace App\Controller;
|
|||
use Catalyst\MenuBundle\Annotation\Menu;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use App\Service\RiderTracker;
|
||||
|
||||
use App\Entity\Rider;
|
||||
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* @Menu(selected="home")
|
||||
*/
|
||||
public function index()
|
||||
public function index(EntityManagerInterface $em, RiderTracker $rider_tracker)
|
||||
{
|
||||
return $this->render('home.html.twig');
|
||||
// get all riders
|
||||
$riders = $em->getRepository(Rider::class)->findAll();
|
||||
|
||||
$locations = [];
|
||||
foreach ($riders as $rider)
|
||||
{
|
||||
// get location for each rider
|
||||
$rider_id = $rider->getID();
|
||||
$coordinates = $rider_tracker->getRiderLocation($rider_id);
|
||||
|
||||
// use rider id as key
|
||||
$locations[$rider_id] = $coordinates;
|
||||
|
||||
}
|
||||
|
||||
$params['riders'] = $locations;
|
||||
|
||||
return $this->render('home.html.twig', $params);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,13 +28,15 @@
|
|||
<div class="row">
|
||||
<div class="col-xl-12">
|
||||
<div class="m-portlet m-portlet--mobile">
|
||||
<div class="m-portlet__body">
|
||||
<div class="form-group m-form__group row">
|
||||
<div class="col-lg-12">
|
||||
<div id="m_gmap" style="height:600px;"></div>
|
||||
<form id="row-form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="POST" }}">
|
||||
<div class="m-portlet__body">
|
||||
<div class="form-group m-form__group row">
|
||||
<div class="col-lg-12">
|
||||
<div id="m_gmap" style="height:600px;"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -61,8 +63,35 @@ function initMap() {
|
|||
mapTypeId: 'roadmap',
|
||||
zoom: 13
|
||||
});
|
||||
|
||||
{% if riders %}
|
||||
{% for object in riders %}
|
||||
var lat = {{ object.getLatitude }};
|
||||
var lng = {{ object.getLongitude }};
|
||||
|
||||
var marker = new google.maps.Marker({
|
||||
position: {
|
||||
lat: lat,
|
||||
lng: lng
|
||||
},
|
||||
});
|
||||
|
||||
marker.setMap(map);
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
}
|
||||
|
||||
function renewMarkers() {
|
||||
$.ajax('{{ path('home') }}', {
|
||||
success: function() {
|
||||
// clear the markers
|
||||
// set the markers again
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
setInterval(renewMarkers, 60 * 1000);
|
||||
|
||||
</script>
|
||||
|
||||
// END google maps stuff
|
||||
|
|
|
|||
Loading…
Reference in a new issue