javascript - 从特定飞行计划航路点获取 GPS 坐标

标签 javascript html dictionary leaflet

我正在制作传单 map ,我想根据从 A 到 B 的航路点(交叉点)列表在上面显示飞行​​计划,例如网站 http://onlineflightplanner.org/它在 map 上显示飞行路线。

我的问题是,如何从航路点获取后面的 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

最佳答案

您确实可以使用像 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));

关于javascript - 从特定飞行计划航路点获取 GPS 坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46977704/

相关文章:

Python:如何处理不可订阅的对象?

javascript - 将对象转换为对象字典

javascript - 如何使用子组件在 ng2 中选择默认选项

javascript - 带有 2 个对话框的 Knockout 按钮单击事件

javascript - 在较大的 div 中打开缩略图

swift - 如何在 Swift 中对字典键进行排序?

javascript - 访问 JSON 数据 - 未定义

javascript - Firefox 不会在 keydown 处理程序中设置 input.value ...但它在调试时有效?

javascript - 将对象移动到顶部或左侧时,jsPlumb 容器不滚动

html - 隐藏由特定 div 引起的水平滚动条