Skip to content

Commit 4b950a3

Browse files
committed
Make coordinates clickable everywhere
1 parent 8f0940f commit 4b950a3

File tree

2 files changed

+22
-36
lines changed

2 files changed

+22
-36
lines changed

js/app.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,25 @@ var format_time_friendly = function(start, end) {
435435
}
436436
};
437437

438+
var format_coordinates = function(lat, lon, name) {
439+
var coords_text;
440+
var ua = navigator.userAgent.toLowerCase();
441+
442+
// determine how to link the coordinates to a native app, if on a mobile device
443+
if(ua.indexOf('iphone') > -1) {
444+
coords_text = '<a href="maps://?q='+lat+','+lon+'">' +
445+
roundNumber(lat, 5) + ', ' + roundNumber(lon, 5) +'</a>';
446+
} else if(ua.indexOf('android') > -1) {
447+
coords_text = '<a href="geo:'+lat+','+lon+'?q='+lat+','+lon+'('+name+')">' +
448+
roundNumber(lat, 5) + ', ' + roundNumber(lon, 5) +'</a>';
449+
} else {
450+
coords_text = '<a href="https://www.google.com/maps/search/?api=1&query='+lat+','+lon+'" target="_blank" rel="noopener noreferrer">' +
451+
roundNumber(lat, 5) + ', ' + roundNumber(lon, 5) +'</a>';
452+
}
453+
454+
return coords_text;
455+
};
456+
438457
// runs every second
439458
var updateTime = function(date) {
440459
// update timebox
@@ -558,12 +577,6 @@ $(window).ready(function() {
558577
$("#main").removeClass("drag");
559578
});
560579

561-
// confirm dialog when launchnig a native map app with coordinates
562-
//$('#main').on('click', '#launch_mapapp', function() {
563-
// var answer = confirm("Launch your maps app?");
564-
// return answer;
565-
//});
566-
567580
// follow vehicle by clicking on data
568581
$('#main').on('click', '.row .data', function() {
569582
var e = $(this).parent();

js/tracker.js

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,21 +1378,7 @@ function updateVehicleInfo(vcallsign, newPosition) {
13781378
hrate_text = imp ? (vehicle.horizontal_rate * 196.850394).toFixed(1) + ' ft/min' : vehicle.horizontal_rate.toFixed(1) + ' m/s';
13791379
}
13801380

1381-
var coords_text;
1382-
var ua = navigator.userAgent.toLowerCase();
1383-
1384-
// determine how to link the vehicle coordinates to a native app, if on a mobile device
1385-
if(ua.indexOf('iphone') > -1) {
1386-
coords_text = '<a id="launch_mapapp" href="maps://?q='+newPosition.gps_lat+','+newPosition.gps_lon+'">' +
1387-
roundNumber(newPosition.gps_lat, 5) + ', ' + roundNumber(newPosition.gps_lon, 5) +'</a>' +
1388-
' <i class="icon-location"></i>';
1389-
} else if(ua.indexOf('android') > -1) {
1390-
coords_text = '<a id="launch_mapapp" href="geo:'+newPosition.gps_lat+','+newPosition.gps_lon+'?q='+newPosition.gps_lat+','+newPosition.gps_lon+'('+vcallsign+')">' +
1391-
roundNumber(newPosition.gps_lat, 5) + ', ' + roundNumber(newPosition.gps_lon, 5) +'</a>' +
1392-
' <i class="icon-location"></i>';
1393-
} else {
1394-
coords_text = roundNumber(newPosition.gps_lat, 5) + ', ' + roundNumber(newPosition.gps_lon, 5);
1395-
}
1381+
var coords_text = format_coordinates(newPosition.gps_lat, newPosition.gps_lon, vcallsign) + ' <i class="icon-location"></i>';
13961382

13971383
// format altitude strings
13981384
var text_alt = Number((imp) ? Math.floor(3.2808399 * parseInt(newPosition.gps_alt)) : parseInt(newPosition.gps_alt)).toLocaleString("us");
@@ -2246,7 +2232,7 @@ function mapInfoBox_handle_path_new(data, vehicle, date) {
22462232
html = "<div style='line-height:16px;position:relative;'>";
22472233
html += "<div>"+data.vehicle+" <span style=''>("+date+")</span></div>";
22482234
html += "<hr style='margin:5px 0px'>";
2249-
html += "<div style='margin-bottom:5px;'><b><i class='icon-location'></i>&nbsp;</b>"+roundNumber(data.gps_lat, 5) + ',&nbsp;' + roundNumber(data.gps_lon, 5)+"</div>";
2235+
html += "<div style='margin-bottom:5px;'><b><i class='icon-location'></i>&nbsp;</b>"+format_coordinates(data.gps_lat, data.gps_lon, data.vehicle)+"</div>";
22502236

22512237
var imp = offline.get('opt_imperial');
22522238
var text_alt = Number((imp) ? Math.floor(3.2808399 * parseInt(data.gps_alt)) : parseInt(data.gps_alt)).toLocaleString("us");
@@ -2345,20 +2331,7 @@ function mapInfoBox_handle_prediction(event) {
23452331
altitude = Math.round(data.alt) + " m";
23462332
}
23472333

2348-
var coords_text;
2349-
var ua = navigator.userAgent.toLowerCase();
2350-
2351-
// determine how to link the vehicle coordinates to a native app, if on a mobile device
2352-
if(ua.indexOf('iphone') > -1) {
2353-
coords_text = '<a href="maps://?q='+data.lat+','+data.lon+'">' +
2354-
roundNumber(data.lat, 5) + ', ' + roundNumber(data.lon, 5) + '</a>';
2355-
} else if(ua.indexOf('android') > -1) {
2356-
coords_text = '<a href="geo:'+data.lat+','+data.lon+'?q='+data.lat+','+data.lon+'(Prediction)">' +
2357-
roundNumber(data.lat, 5) + ', ' + roundNumber(data.lon, 5) +'</a>';
2358-
} else {
2359-
coords_text = '<a href="https://www.google.com/maps/search/?api=1&query='+data.lat+','+data.lon+'" target="_blank" rel="noopener noreferrer">' +
2360-
roundNumber(data.lat, 5) + ', ' + roundNumber(data.lon, 5) +'</a>';
2361-
}
2334+
var coords_text = format_coordinates(data.lat, data.lon, "Prediction");
23622335

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

0 commit comments

Comments
 (0)