最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - Extract GPS data from EXIF data in JavaScript - Stack Overflow

programmeradmin7浏览0评论

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.

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.

Share Improve this question edited Jan 20, 2020 at 12:40 noetix 4,9433 gold badges28 silver badges48 bronze badges asked Apr 25, 2016 at 11:23 Deepak SharmaDeepak Sharma 1,1471 gold badge12 silver badges23 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 9

Oh, i just e 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

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.

发布评论

评论列表(0)

  1. 暂无评论