1

I'm developing a Leaflet Map, and I would like to display the flight plan on it, based on a list of waypoints (intersection) from A to B, like the site http://onlineflightplanner.org/ where it displays the flight route on the map.

My question is, how to get the behind gps coordinates from a waypoint (ex: ADABI : N44°4943.15 / W000°42'55.24''? is there any javascript library which can do this ? Thanks a lot

List of waypoints along with its gps coordinates (from onlineflightplanner.org)

And Display on Map

bluewonder
  • 767
  • 2
  • 10
  • 18

1 Answers1

2

You can indeed use a library like Javascript GeoPoint Library, but such a conversion is rather easy to implement. Furthermore, the mentioned library expects you to already know which value is latitude (northing) and which one is longitude (easting), which may not be the case if your input is "N44°49'43.15 / W000°42'55.24''" as you suggest.

Building on Converting latitude and longitude to decimal values, we can easily make a specific conversion utility that should fit your case:

var input = "N44°49'43.15 / W000°42'55.24''";

function parseDMS(input) {
  var halves = input.split('/'); // Separate northing from easting.
  return { // Ready to be fed into Leaflet.
    lat: parseDMSsingle(halves[0].trim()),
    lng: parseDMSsingle(halves[1].trim())
  };
}

function parseDMSsingle(input) {
  var direction = input[0]; // First char is direction (N, E, S or W).
  input = input.substr(1);
  var parts = input.split(/[^\d\w.]+/);
  // 0: degrees, 1: minutes, 2: seconds; each can have decimals.
  return convertDMSToDD(
    parseFloat(parts[0]) || 0, // Accept missing value.
    parseFloat(parts[1]) || 0,
    parseFloat(parts[2]) || 0,
    direction
  );
}

function convertDMSToDD(degrees, minutes, seconds, direction) {
  var dd = degrees + minutes/60 + seconds/(60*60);

  if (direction == "S" || direction == "W") {
      dd = dd * -1;
  } // Don't do anything for N or E
  return dd;
}

console.log(input);
console.log(parseDMS(input));
ghybs
  • 47,565
  • 6
  • 74
  • 99