How to get distance between specific nodes.

Q&A about the latest versions
Post Reply
hkreslone
Posts: 5
Joined: Mon Mar 22, 2021 2:12 pm

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
Bostjan
Posts: 421
Joined: Fri Oct 17, 2008 4:06 pm
Location: Slovenia, EU
Contact:

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";
}
hkreslone
Posts: 5
Joined: Mon Mar 22, 2021 2:12 pm

Thank you!
Post Reply