Skip to content

Instantly share code, notes, and snippets.

@dyjjones
Last active August 29, 2015 14:04
Show Gist options
  • Save dyjjones/71beb2ac7c294ab16871 to your computer and use it in GitHub Desktop.
Save dyjjones/71beb2ac7c294ab16871 to your computer and use it in GitHub Desktop.
Command line function for lat/lon of picture.
//#!/usr/bin/node
// neg = node exif geolocation, latitude and longitude
// Add to your path, then use as: neg.js [path to image]
// chmod +x this file on download, move to a path folder
// or add to path manually
var im = require('imagemagick');
if (process.argv.length === 3) {
im.readMetadata(process.argv[2], function (err, metadata) {
if (err) throw err;
if (metadata.exif) {
if (metadata.exif.gpsLatitude && metadata.exif.gpsLongitude) {
console.log('Raw Latitude:\t\t', metadata.exif.gpsLatitude);
console.log('Raw Longitude:\t\t', metadata.exif.gpsLongitude);
var splitLat = metadata.exif.gpsLatitude.split(', ');
var splitLon = metadata.exif.gpsLongitude.split(', ');
var decimalLat = parseInt(splitLat[0].split('/')[0]) +
(parseInt(splitLat[1].split('/')[0]) / (60.0 * parseInt(splitLat[1].split('/')[1]))) +
(parseInt(splitLat[2].split('/')[0]) / (3600.0 * parseInt(splitLat[2].split('/')[1])));
var decimalLon = parseInt(splitLon[0].split('/')[0]) +
(parseInt(splitLon[1].split('/')[0]) / (60.0 * parseInt(splitLon[1].split('/')[1]))) +
(parseInt(splitLon[2].split('/')[0]) / (3600.0 * parseInt(splitLon[2].split('/')[1])));
console.log('Decimal Latitude:\t', decimalLat);
console.log('Decimal Longitude:\t', decimalLon);
}
else {
console.log('No latitude and longitude available.');
}
}
else {
console.log('No exif data.');
}
});
}
else
console.log('Usage: `neg [path to image]`');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment