From 94d37e9edfddcc074d59a2283533b8b05be8e486 Mon Sep 17 00:00:00 2001 From: Heliane Ly Date: Thu, 25 Oct 2018 11:30:57 +0200 Subject: [PATCH] fix negative gps coordinates pack error --- piexif.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/piexif.js b/piexif.js index f5cf723..d624e45 100644 --- a/piexif.js +++ b/piexif.js @@ -2440,9 +2440,10 @@ SOFTWARE. that.GPSHelper = { degToDmsRational:function (degFloat) { - var minFloat = degFloat % 1 * 60; + var degAbs = Math.abs(degFloat); + var minFloat = degAbs % 1 * 60; var secFloat = minFloat % 1 * 60; - var deg = Math.floor(degFloat); + var deg = Math.floor(degAbs); var min = Math.floor(minFloat); var sec = Math.round(secFloat * 100); @@ -2450,12 +2451,12 @@ SOFTWARE. }, dmsRationalToDeg:function (dmsArray, ref) { - var sign = (ref === 'S' || ref === 'W') ? -1.0 : 1.0; - var deg = sign * dmsArray[0][0] / dmsArray[0][1] + - dmsArray[1][0] / dmsArray[1][1] / 60.0 + - dmsArray[2][0] / dmsArray[2][1] / 3600.0; + var sign = (ref === 'S' || ref === 'W') ? -1.0 : 1.0; + var deg = dmsArray[0][0] / dmsArray[0][1] + + dmsArray[1][0] / dmsArray[1][1] / 60.0 + + dmsArray[2][0] / dmsArray[2][1] / 3600.0; - return deg; + return deg * sign; } };