I am building a quite large VT (around 130 nodes) and I want to have the option to calculate and show distance between two chosen nodes. All nodes have gps data (longitude, latitude) added in tour browser. Is there an option to access this data, calculate distance and show it on screen?
Leszek
How to get distance between specific nodes.
Hi,
the script is already implemented a couple of years. The example: https://www.burger.si/KSA/360/KSA.html
code for the textbox:
javascript:'';
var R = 6371.0; // km
var src=player.userdata;
var dest=this.ggUserdata;
var dLat = (Number(dest.latitude) - Number(src.latitude)) * (Math.PI / 180.0);
var dLon = (Number(dest.longitude) - Number(src.longitude)) * (Math.PI / 180.0);
var lat1Rad = Number(src.latitude) * (Math.PI / 180.0);
var lat2Rad = Number(dest.latitude) * (Math.PI / 180.0);
var a = Math.sin(dLat / 2.0) * Math.sin(dLat / 2.0) + Math.sin(dLon / 2.0) * Math.sin(dLon / 2.0) * Math.cos(lat1Rad) * Math.cos(lat2Rad);
var c = 2.0 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
var d = R * c;
if (d>1) {
this._text_dist2__text.innerHTML=d.toFixed(1) + "km";
} else {
this._text_dist2__text.innerHTML=(d*1000).toFixed(0) + "m";
}
the script is already implemented a couple of years. The example: https://www.burger.si/KSA/360/KSA.html
code for the textbox:
javascript:'';
var R = 6371.0; // km
var src=player.userdata;
var dest=this.ggUserdata;
var dLat = (Number(dest.latitude) - Number(src.latitude)) * (Math.PI / 180.0);
var dLon = (Number(dest.longitude) - Number(src.longitude)) * (Math.PI / 180.0);
var lat1Rad = Number(src.latitude) * (Math.PI / 180.0);
var lat2Rad = Number(dest.latitude) * (Math.PI / 180.0);
var a = Math.sin(dLat / 2.0) * Math.sin(dLat / 2.0) + Math.sin(dLon / 2.0) * Math.sin(dLon / 2.0) * Math.cos(lat1Rad) * Math.cos(lat2Rad);
var c = 2.0 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
var d = R * c;
if (d>1) {
this._text_dist2__text.innerHTML=d.toFixed(1) + "km";
} else {
this._text_dist2__text.innerHTML=(d*1000).toFixed(0) + "m";
}