Extracting GPS coordinates from exif
This commit is contained in:
1 parent
d44f9a257e
commit
4df529abb7
2 files changed
+30
-10
No files matched your search
@@ -0,0 +1,26 @@
|
||||
import piexif from 'piexifjs';
|
||||
|
||||
export const getDate = (exifObj: any) => {
|
||||
const dateSegments = exifObj.Exif[piexif.ExifIFD.DateTimeOriginal].split(' ');
|
||||
const date = `${dateSegments[0].replaceAll(':', '-')}T${dateSegments[1]}.${
|
||||
exifObj.Exif[piexif.ExifIFD.SubSecTimeOriginal] || '0'
|
||||
}${exifObj.Exif[piexif.ExifIFD.OffsetTimeOriginal]}`;
|
||||
return new Date(date);
|
||||
};
|
||||
|
||||
export const getGps = (exifObj: any) => {
|
||||
const toNumber = (start: number) => {
|
||||
const sign = ['N', 'E'].includes(exifObj.GPS[start]) ? 1 : -1;
|
||||
const value = exifObj.GPS[start + 1];
|
||||
return (
|
||||
sign *
|
||||
(value[0][0] / value[0][1] +
|
||||
(value[1][0] / value[1][1] + value[2][0] / value[2][1] / 60) / 60)
|
||||
);
|
||||
};
|
||||
return {
|
||||
latitude: toNumber(1),
|
||||
longitude: toNumber(3),
|
||||
elevation: exifObj.GPS[6][0] / exifObj.GPS[6][1],
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user