Closed mohsen1 closed 9 years ago
Thank you. My lat-long in in this format:
"latitude": 36.613230478624,
"longitude": -121.93234200195,
How can I use these numbers?
exifObj["GPS"][piexif.GPSIFD.GPSLatitudeRef] = "N"; exifObj["GPS"][piexif.GPSIFD.GPSLatitude] = [366132304, 10000000], exifObj["GPS"][piexif.GPSIFD.GPSLongitudeRef] = "W"; exifObj["GPS"][piexif.GPSIFD.GPSLongitude] = [1219323420, 10000000];
Two questions:
N
and W
values are coming from? Are they relative to lat-long numbers?GPSLongitude
while my longitude was negative? latitude >= 0: North latitude -> "N" latitude < 0: South latitude -> "S" longitude >= 0: East longitude -> "E" longitude < 0: West longitude -> "W"
Thank you!
Anytime.
Hi, great library guys!
The above-suggested way of assigning latitude & longitude to an array of two – [numerator, denominator] – did not work for me. The resulting image was still not bearing any GPS info when i opened it with OS X Preview app.
What did work however was representing the coordinates as multidimensional array of deegrees, minutes and seconds like this:
var data = {
lat: 59.43553989213321,
lng: 24.73842144012451
}
exifObj["GPS"][piexif.GPSIFD.GPSLatitudeRef] = data.lat < 0 ? 'S' : 'N'
exifObj["GPS"][piexif.GPSIFD.GPSLatitude] = degToDmsRational(data.lat)
exifObj["GPS"][piexif.GPSIFD.GPSLongitudeRef] = data.lng < 0 ? 'W' : 'E'
exifObj["GPS"][piexif.GPSIFD.GPSLongitude] = degToDmsRational(data.lng)
/**
* degToDmsRational(59.43553989213321) -> [[59, 1], [26, 1], [794, 100]]
*/
function degToDmsRational(degFloat) {
var minFloat = degFloat % 1 * 60
var secFloat = minFloat % 1 * 60
var deg = Math.floor(degFloat)
var min = Math.floor(minFloat)
var sec = Math.round(secFloat * 100)
return [[deg, 1], [min, 1], [sec, 100]]
}
p.s. i ran my code in Google Chrome browser and the image was parsed with FileReader api as dataURL
Thank you. My way was wrong. Rational value as lat or lon has 3 length, not one length.
if you pass negative coordinates fails, you need to pass to positive the result
function degToDmsRational(degFloat) {
var minFloat = degFloat % 1 * 60
var secFloat = minFloat % 1 * 60
var deg = Math.floor(degFloat)
var min = Math.floor(minFloat)
var sec = Math.round(secFloat * 100)
deg = Math.abs(deg) * 1
min = Math.abs(min) * 1
sec = Math.abs(sec) * 1
return [[deg, 1], [min, 1], [sec, 100]]
}
I too had problems getting GPS to appear. ipsips's solution works for showing the lat/lon, but I still cannot get any other GPS fields to display. Any suggestions or sample code that actually works? In photos, Altitude is an object of num & den. Also, any ideas on displaying exifObj["GPS"][piexif.GPSIFD.GPSDOP] ? Please provide a working example so we can get them to work. Thanks.
node example, north 37.429289 and west 122.138162.