Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get Latitude and Longitude from EXIF using PIL
import PIL.Image
get_float = lambda x: float(x[0]) / float(x[1])
def convert_to_degrees(value):
d = get_float(value[0])
m = get_float(value[1])
s = get_float(value[2])
return d + (m / 60.0) + (s / 3600.0)
def get_lat_lon(info):
try:
gps_latitude = info[34853][2]
gps_latitude_ref = info[34853][1]
gps_longitude = info[34853][4]
gps_longitude_ref = info[34853][3]
lat = convert_to_degrees(gps_latitude)
if gps_latitude_ref != "N":
lat *= -1
lon = convert_to_degrees(gps_longitude)
if gps_longitude_ref != "E":
lon *= -1
return lat, lon
except KeyError:
return None
@arpanchal

This comment has been minimized.

Copy link

@arpanchal arpanchal commented Nov 2, 2018

Hi,
what is 'info' in the argument?
Is it gps exif info?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment