Reputation: 1137
I would like to extract the GPS Exif tag from pictures using NodeJS. I got data in this format:
{
"gps": {
"GPSTimeStamp": [2147483647, 76, 41],
"GPSLongitude": [76, 41, 56.622],
"GPSLatitude": [30, 43, 8.754],
"GPSAltitude": 0,
"GPSDateStamp": "14615748802"
}
}
Is there any way to convert it into latitude and longitude?
When I am checking Exif data in Android it shows me proper latitude and longitude, but in NodeJS I am getting data in this format.
Upvotes: 3
Views: 4890
Reputation: 302
I know this may be already solved but I'd like to offer alternative solution, for the people stumbling upon this question.
It seems like you are using some Node.js library that gives you these raw lat/long data and it's up to you to convert them. There is a new library exifr that does this for you automatically. It's maintained, actively developed library with focus on performance and works in both nodejs and browser.
async function getExif() {
let output = await exifr.parse(imgBuffer)
console.log('gps', output.latitude, output.longitude)
}
You can also try out the library's playground and experiment with images and their output, or check out the repository and docs.
Upvotes: 2
Reputation: 1137
Oh, i just come to know the concept og digree,minute,seconds and direction. i got three values in array as digree , minute and seconds
To parse your input use the following.
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]);
}
The following will convert your DMS to 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;
}
So your input would produce the following:
36°57'9" N = 36.9525000
110°4'21" W = -110.0725000
Upvotes: 8