Skip to content

Commit b2941f6

Browse files
committed
Move coordinate formatting into a function
1 parent b243005 commit b2941f6

File tree

2 files changed

+21
-31
lines changed

2 files changed

+21
-31
lines changed

js/app.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,25 @@ var format_time_friendly = function(start, end) {
445445
}
446446
};
447447

448+
var format_coordinates = function(lat, lon, name) {
449+
var coords_text;
450+
var ua = navigator.userAgent.toLowerCase();
451+
452+
// determine how to link the coordinates to a native app, if on a mobile device
453+
if(ua.indexOf('iphone') > -1) {
454+
coords_text = '<a href="maps://?q='+lat+','+lon+'">' +
455+
roundNumber(lat, 5) + ', ' + roundNumber(lon, 5) +'</a>';
456+
} else if(ua.indexOf('android') > -1) {
457+
coords_text = '<a href="geo:'+lat+','+lon+'?q='+lat+','+lon+'('+name+')">' +
458+
roundNumber(lat, 5) + ', ' + roundNumber(lon, 5) +'</a>';
459+
} else {
460+
coords_text = '<a href="https://www.google.com/maps/search/?api=1&query='+lat+','+lon+'" target="_blank" rel="noopener noreferrer">' +
461+
roundNumber(lat, 5) + ', ' + roundNumber(lon, 5) +'</a>';
462+
}
463+
464+
return coords_text;
465+
};
466+
448467
// runs every second
449468
var updateTime = function(date) {
450469
// update timebox

js/tracker.js

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,23 +1799,7 @@ function updateVehicleInfo(vcallsign, newPosition) {
17991799
hrate_text = imp ? (vehicle.horizontal_rate * 196.850394).toFixed(1) + ' ft/min' : vehicle.horizontal_rate.toFixed(1) + ' m/s';
18001800
}
18011801

1802-
var coords_text;
1803-
var ua = navigator.userAgent.toLowerCase();
1804-
1805-
// determine how to link the vehicle coordinates to a native app, if on a mobile device
1806-
if(ua.indexOf('iphone') > -1) {
1807-
coords_text = '<a href="maps://?q='+newPosition.gps_lat+','+newPosition.gps_lon+'">' +
1808-
roundNumber(newPosition.gps_lat, 5) + ', ' + roundNumber(newPosition.gps_lon, 5) +'</a>' +
1809-
' <i class="icon-location"></i>';
1810-
} else if(ua.indexOf('android') > -1) {
1811-
coords_text = '<a href="geo:'+newPosition.gps_lat+','+newPosition.gps_lon+'?q='+newPosition.gps_lat+','+newPosition.gps_lon+'('+vcallsign+')">' +
1812-
roundNumber(newPosition.gps_lat, 5) + ', ' + roundNumber(newPosition.gps_lon, 5) +'</a>' +
1813-
' <i class="icon-location"></i>';
1814-
} else {
1815-
coords_text = '<a href="https://www.google.com/maps/search/?api=1&query='+newPosition.gps_lat+','+newPosition.gps_lon+'" target="_blank" rel="noopener noreferrer">' +
1816-
roundNumber(newPosition.gps_lat, 5) + ', ' + roundNumber(newPosition.gps_lon, 5) +'</a>' +
1817-
' <i class="icon-location"></i>';
1818-
}
1802+
var coords_text = format_coordinates(newPosition.gps_lat, newPosition.gps_lon, vcallsign) + ' <i class="icon-location"></i>';
18191803

18201804
// format altitude strings
18211805
var text_alt = Number((imp) ? Math.floor(3.2808399 * parseInt(newPosition.gps_alt)) : parseInt(newPosition.gps_alt)).toLocaleString("us");
@@ -2931,20 +2915,7 @@ function mapInfoBox_handle_prediction(event) {
29312915
altitude = Math.round(data.alt) + " m";
29322916
}
29332917

2934-
var coords_text;
2935-
var ua = navigator.userAgent.toLowerCase();
2936-
2937-
// determine how to link the vehicle coordinates to a native app, if on a mobile device
2938-
if(ua.indexOf('iphone') > -1) {
2939-
coords_text = '<a href="maps://?q='+data.lat+','+data.lon+'">' +
2940-
roundNumber(data.lat, 5) + ', ' + roundNumber(data.lon, 5) + '</a>';
2941-
} else if(ua.indexOf('android') > -1) {
2942-
coords_text = '<a href="geo:'+data.lat+','+data.lon+'?q='+data.lat+','+data.lon+'(Prediction)">' +
2943-
roundNumber(data.lat, 5) + ', ' + roundNumber(data.lon, 5) +'</a>';
2944-
} else {
2945-
coords_text = '<a href="https://www.google.com/maps/search/?api=1&query='+data.lat+','+data.lon+'" target="_blank" rel="noopener noreferrer">' +
2946-
roundNumber(data.lat, 5) + ', ' + roundNumber(data.lon, 5) +'</a>';
2947-
}
2918+
var coords_text = format_coordinates(data.lat, data.lon, "Prediction");
29482919

29492920
mapInfoBox.setContent("<pre>" +
29502921
formatDate(new Date(parseInt(data.time) * 1000), true) + "\n\n" +

0 commit comments

Comments
 (0)