我想使用NODEJS从图片中提取GPS EXIF标签。我得到了这种格式的数据:
{
"gps":
{
"GPSTimeStamp": [2147483647, 76, 41],
"GPSLongitude": [76, 41, 56.622],
"GPSLatitude": [30, 43, 8.754],
"GPSAltitude": 0,
"GPSDateStamp": "14615748802"
}
}
有没有办法将其转换为纬度和经度。当我在android中检查exif数据时。它显示了我适当的研究和经度。但是在NODE JS中,我正在以这种格式获取数据。
答案 0 :(得分:3)
哦,我刚刚开始了解og digree,分钟,秒和方向的概念。 我在数组中得到三个值为digree,minute和seconds
要解析您的输入,请使用以下内容。
function ParseDMS(input) {
var parts = input.split(/[^\d\w]+/);
var lat = ConvertDMSToDD(parts[0], parts[1], parts[2], parts[3]);
var lng = ConvertDMSToDD(parts[4], parts[5], parts[6], parts[7]);
}
以下内容将您的DMS转换为DD
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;
}
所以你的输入会产生以下结果:
36°57'9" N = 36.9525000
110°4'21" W = -110.0725000
答案 1 :(得分:0)
我知道这可能已经解决了,但是我想提供替代解决方案,因为人们在这个问题上绊脚石。
似乎您正在使用一些Node.js库,该库为您提供这些原始的经/纬度数据,并且要由您将其转换。有一个新的库exifr会自动为您执行此操作。它是维护,积极开发的,注重性能的库,可在nodejs和浏览器中使用。
async function getExif() {
let output = await exifr.parse(imgBuffer)
console.log('gps', output.latitude, output.longitude)
}
您还可以尝试使用库中的playground并尝试图像及其输出,或者检查repository and docs。