作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在制作传单 map ,我想根据从 A 到 B 的航路点(交叉点)列表在上面显示飞行计划,例如网站 http://onlineflightplanner.org/它在 map 上显示飞行路线。
我的问题是,如何从航路点获取后面的 gps 坐标(例如:ADABI : N44°4943.15/W000°42'55.24''?是否有任何 javascript 库可以做到这一点?非常感谢
最佳答案
您确实可以使用像 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/
在休眠状态挂接到我的JBoss AS 7.1之前,我试图在应用程序中运行flyway。我尝试使用@javax.ejb.Startup批注,但是在初始化Hibernate和检查数据库方案之后,此批注便会
我想将 div 移动到另一个 div 中。现在它们飞过整个页面。 我应该在代码中更改什么才能使其正常工作? $(document).ready(function() { $('.balloon')
我是一名优秀的程序员,十分优秀!