diff --git a/app/Http/Controllers/TrackerController.php b/app/Http/Controllers/TrackerController.php index a0dd212..515d68f 100644 --- a/app/Http/Controllers/TrackerController.php +++ b/app/Http/Controllers/TrackerController.php @@ -149,6 +149,8 @@ class TrackerController extends Controller case 200: $data = json_decode($response->getBody()); + $data->trip->locations = $this->decode_polyline($data->trip->route); + // Cache the downloaded file if it does not exist locally. if (Storage::disk('local')->missing($tripFileName)) { Log::debug("Caching new trip file '{$tripFileName}'."); @@ -173,8 +175,6 @@ class TrackerController extends Controller } } - $data->trip->locations = $this->decode_polyline($data->trip->route); - return $data->trip; default: // TODO: Add proper error handling. diff --git a/resources/views/tracker.blade.php b/resources/views/tracker.blade.php index fb60e1d..b024363 100644 --- a/resources/views/tracker.blade.php +++ b/resources/views/tracker.blade.php @@ -51,7 +51,7 @@ /* * Initialise the map */ - var map = L.map('map');//.setView([{{ end($trip->locations)->latitude }}, {{ end($trip->locations)->longitude }}], 7); + var map = L.map('map'); L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 19, attribution: 'OpenStreetMap' @@ -127,8 +127,8 @@ */ map.fitBounds([ @if ($trip->is_active) - @foreach(array_slice(array_reverse($trip->locations), 0, 25) as $location) - [{{ $location->latitude }}, {{$location->longitude }}], + @foreach(array_slice(array_reverse($trip->checkins), 0, 25) as $checkin) + [{{ $checkin->location->latitude }}, {{$checkin->location->longitude }}], @endforeach @else @foreach($trip->locations as $location)