从特定的航班计划航路点获取GPS坐标

时间:2017-10-27 14:42:28

标签: javascript html dictionary leaflet

我正在开发一个传单地图,我想根据从A到B的航路点(交叉点)列表显示航班计划,就像它显示航班的网站http://onlineflightplanner.org/一样路线在地图上。

我的问题是,如何从一个航路点获得背后的GPS坐标(例如:ADABI:N44°4943.15 / W000°42'55.24''?有没有任何javascript库可以做到这一点?非常感谢

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

And Display on Map

1 个答案:

答案 0 :(得分:2)

您确实可以使用像Javascript GeoPoint Library这样的库,但这样的转换很容易实现。此外,所提到的图书馆希望您已经知道哪个值是纬度(北向)以及哪个是经度(东向),如果您的输入是"N44°49'43.15 / W000°42'55.24''",则可能不是这样。

Converting latitude and longitude to decimal values的基础上,我们可以轻松制作适合您案例的特定转化工具:



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));