Nikitenko Maxim (Sets88)

Personal page

Python - Show GeoTag on map

Sometimes i need to see, where current photo were made, using exif GPS data in photo.

Tried to find some application for Linux, but found nothing.

Well, nothing complicated here, to create new one.

Source code
#! /usr/bin/python

import webbrowser
import pyexiv2
import os
import sys

GOOGLE_URL = ",%s"
YANDEX_URL = ",%s"

def get_exiv_data(filename, itime=False):
    if not os.path.exists(filename):
        return False
    metadata = pyexiv2.ImageMetadata(filename)
        return False
        return metadata

def gps_data_to_float(ldata, ref):
    float_data = float(ldata.value[0].numerator) / ldata.value[0].denominator + float(ldata.value[1].numerator) / ldata.value[1].denominator / 60 + float(ldata.value[2].numerator) / ldata.value[2].denominator / 3600
    if ref == 'S' or ref == 'W':
        return -float_data
        return float_data

def main(exiv, map_url):
    if exiv and "Exif.GPSInfo.GPSLatitude" in exiv and "Exif.GPSInfo.GPSLongitude" in exiv:
        latitude = gps_data_to_float(exiv["Exif.GPSInfo.GPSLatitude"], exiv["Exif.GPSInfo.GPSLatitudeRef"])
        longitude = gps_data_to_float(exiv["Exif.GPSInfo.GPSLongitude"], exiv["Exif.GPSInfo.GPSLongitudeRef"])
        url = map_url % (latitude, longitude)
        print url
        print "No GPS data in exif"

if __name__ == '__main__':
    if len(sys.argv) > 1:
        main(get_exiv_data(sys.argv[1]), GOOGLE_URL)
        print "Shows gps data from exif on map\nUsage:\n%s " % (sys.argv[0])

And then, it's not hard to attach it to nautilus for example and by clicking mouse right button, there will be a menu item, which allow you to open a map in browser.