Skip to content

Commit 72dcf4b

Browse files
committed
fix crash
1 parent ebe984e commit 72dcf4b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

js/tracker.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,18 +2591,18 @@ function addPosition(position) {
25912591

25922592
var search_matches = vehicle.positions_ts.filter(searchPositions)
25932593

2594-
if (search_matches.length > 0 && search_matches[search_matches.length-1] >= search_ts - 5000) {
2594+
if (search_matches.length > 0 && search_matches[search_matches.length-1] >= search_ts - 5000 && vehicle.positions.length >= search_matches.length) {
25952595
var search_match = search_matches[search_matches.length-1]
25962596
var dtt = (curr_ts - search_match) / 1000;
25972597

25982598
// calculate vertical rate
2599-
var rate = (position.gps_alt - vehicle.positions_alts[search_matches.length]) / dtt;
2599+
var rate = (position.gps_alt - vehicle.positions_alts[search_matches.length-1]) / dtt;
26002600
if (!isNaN(rate) && isFinite(rate)) {
26012601
vehicle.ascent_rate = 0.5 * rate + 0.5 * vehicle.ascent_rate;
26022602
}
26032603

26042604
// calculate horizontal rate
2605-
horizontal_rate_temp = new_latlng.distanceTo(vehicle.positions[search_matches.length]) / dtt;
2605+
horizontal_rate_temp = new_latlng.distanceTo(vehicle.positions[search_matches.length-1]) / dtt;
26062606
if (!isNaN(horizontal_rate_temp) && isFinite(horizontal_rate_temp)) {
26072607
vehicle.horizontal_rate = horizontal_rate_temp;
26082608
}

0 commit comments

Comments
 (0)