Index: src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
===================================================================
--- src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java	(révision 6080)
+++ src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java	(copie de travail)
@@ -64,11 +64,12 @@
 
 import com.drew.imaging.jpeg.JpegMetadataReader;
 import com.drew.lang.CompoundException;
+import com.drew.lang.GeoLocation;
 import com.drew.lang.Rational;
 import com.drew.metadata.Directory;
 import com.drew.metadata.Metadata;
 import com.drew.metadata.MetadataException;
-import com.drew.metadata.exif.ExifDirectory;
+import com.drew.metadata.exif.ExifIFD0Directory;
 import com.drew.metadata.exif.GpsDirectory;
 
 public class GeoImageLayer extends Layer implements PropertyChangeListener, JumpToMarkerLayer {
@@ -507,24 +508,26 @@
 
     private static void extractExif(ImageEntry e) {
 
-        double deg;
-        double min, sec;
-        double lon, lat;
-        Metadata metadata = null;
-        Directory dirExif = null, dirGps = null;
+        Metadata metadata;
+        Directory dirExif;
+        GpsDirectory dirGps;
 
         try {
             metadata = JpegMetadataReader.readMetadata(e.getFile());
-            dirExif = metadata.getDirectory(ExifDirectory.class);
+            dirExif = metadata.getDirectory(ExifIFD0Directory.class);
             dirGps = metadata.getDirectory(GpsDirectory.class);
         } catch (CompoundException p) {
             e.setExifCoor(null);
             e.setPos(null);
             return;
+        } catch (IOException p) {
+            e.setExifCoor(null);
+            e.setPos(null);
+            return;
         }
 
         try {
-            int orientation = dirExif.getInt(ExifDirectory.TAG_ORIENTATION);
+            int orientation = dirExif.getInt(ExifIFD0Directory.TAG_ORIENTATION);
             e.setExifOrientation(orientation);
         } catch (MetadataException ex) {
         }
@@ -540,63 +543,24 @@
         }
 
         try {
-            // longitude
-
-            Rational[] components = dirGps.getRationalArray(GpsDirectory.TAG_GPS_LONGITUDE);
-
-            deg = components[0].doubleValue();
-            min = components[1].doubleValue();
-            sec = components[2].doubleValue();
-
-            if (Double.isNaN(deg) && Double.isNaN(min) && Double.isNaN(sec))
-                throw new IllegalArgumentException();
-
-            lon = (Double.isNaN(deg) ? 0 : deg + (Double.isNaN(min) ? 0 : (min / 60)) + (Double.isNaN(sec) ? 0 : (sec / 3600)));
-
-            if (dirGps.getString(GpsDirectory.TAG_GPS_LONGITUDE_REF).charAt(0) == 'W') {
-                lon = -lon;
-            }
-
-            // latitude
-
-            components = dirGps.getRationalArray(GpsDirectory.TAG_GPS_LATITUDE);
-
-            deg = components[0].doubleValue();
-            min = components[1].doubleValue();
-            sec = components[2].doubleValue();
-
-            if (Double.isNaN(deg) && Double.isNaN(min) && Double.isNaN(sec))
-                throw new IllegalArgumentException();
-
-            lat = (Double.isNaN(deg) ? 0 : deg + (Double.isNaN(min) ? 0 : (min / 60)) + (Double.isNaN(sec) ? 0 : (sec / 3600)));
-
-            if (Double.isNaN(lat))
-                throw new IllegalArgumentException();
-
-            if (dirGps.getString(GpsDirectory.TAG_GPS_LATITUDE_REF).charAt(0) == 'S') {
-                lat = -lat;
-            }
-
-            // Store values
-
-            e.setExifCoor(new LatLon(lat, lon));
-            e.setPos(e.getExifCoor());
-
-        } catch (CompoundException p) {
-            // Try to read lon/lat as double value (Nonstandard, created by some cameras -> #5220)
-            try {
-                Double longitude = dirGps.getDouble(GpsDirectory.TAG_GPS_LONGITUDE);
-                Double latitude = dirGps.getDouble(GpsDirectory.TAG_GPS_LATITUDE);
-                if (longitude == null || latitude == null)
-                    throw new CompoundException("");
-
-                // Store values
-
-                e.setExifCoor(new LatLon(latitude, longitude));
+            GeoLocation location = dirGps.getGeoLocation();
+            if (location != null) {
+                e.setExifCoor(new LatLon(location.getLatitude(), location.getLongitude()));
                 e.setPos(e.getExifCoor());
-            } catch (CompoundException ex) {
-                e.setExifCoor(null);
-                e.setPos(null);
+            } else {
+                // Try to read lon/lat as double value (Nonstandard, created by some cameras -> #5220)
+                try {
+                    Double longitude = dirGps.getDouble(GpsDirectory.TAG_GPS_LONGITUDE);
+                    Double latitude = dirGps.getDouble(GpsDirectory.TAG_GPS_LATITUDE);
+    
+                    // Store values
+    
+                    e.setExifCoor(new LatLon(latitude, longitude));
+                    e.setPos(e.getExifCoor());
+                } catch (CompoundException ex) {
+                    e.setExifCoor(null);
+                    e.setPos(null);
+                }
             }
         } catch (Exception ex) { // (other exceptions, e.g. #5271)
             System.err.println("Error reading EXIF from file: "+ex);
Index: src/org/openstreetmap/josm/tools/ExifReader.java
===================================================================
--- src/org/openstreetmap/josm/tools/ExifReader.java	(révision 6080)
+++ src/org/openstreetmap/josm/tools/ExifReader.java	(copie de travail)
@@ -2,9 +2,9 @@
 package org.openstreetmap.josm.tools;
 
 import java.io.File;
+import java.io.IOException;
 import java.text.ParseException;
 import java.util.Date;
-import java.util.Iterator;
 
 import com.drew.imaging.jpeg.JpegMetadataReader;
 import com.drew.imaging.jpeg.JpegProcessingException;
@@ -12,7 +12,8 @@
 import com.drew.metadata.Metadata;
 import com.drew.metadata.MetadataException;
 import com.drew.metadata.Tag;
-import com.drew.metadata.exif.ExifDirectory;
+import com.drew.metadata.exif.ExifIFD0Directory;
+import com.drew.metadata.exif.ExifSubIFDDirectory;
 
 /**
  * Read out exif file information from a jpeg file
@@ -25,15 +26,14 @@
             Metadata metadata = JpegMetadataReader.readMetadata(filename);
             String dateStr = null;
             OUTER:
-            for (Iterator<Directory> dirIt = metadata.getDirectoryIterator(); dirIt.hasNext();) {
-                for (Iterator<Tag> tagIt = dirIt.next().getTagIterator(); tagIt.hasNext();) {
-                    Tag tag = tagIt.next();
-                    if (tag.getTagType() == ExifDirectory.TAG_DATETIME_ORIGINAL /* 0x9003 */) {
+            for (Directory dirIt : metadata.getDirectories()) {
+                for (Tag tag : dirIt.getTags()) {
+                    if (tag.getTagType() == ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL /* 0x9003 */) {
                         dateStr = tag.getDescription();
                         break OUTER; // prefer this tag
                     }
-                    if (tag.getTagType() == ExifDirectory.TAG_DATETIME /* 0x0132 */ ||
-                        tag.getTagType() == ExifDirectory.TAG_DATETIME_DIGITIZED /* 0x9004 */) {
+                    if (tag.getTagType() == ExifIFD0Directory.TAG_DATETIME /* 0x0132 */ ||
+                        tag.getTagType() == ExifSubIFDDirectory.TAG_DATETIME_DIGITIZED /* 0x9004 */) {
                         dateStr = tag.getDescription();
                     }
                 }
@@ -54,12 +54,14 @@
         Integer orientation = null;
         try {
             final Metadata metadata = JpegMetadataReader.readMetadata(filename);
-            final Directory dir = metadata.getDirectory(ExifDirectory.class);
-            orientation = dir.getInt(ExifDirectory.TAG_ORIENTATION);
+            final Directory dir = metadata.getDirectory(ExifIFD0Directory.class);
+            orientation = dir.getInt(ExifIFD0Directory.TAG_ORIENTATION);
         } catch (JpegProcessingException e) {
             e.printStackTrace();
         } catch (MetadataException e) {
             e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
         }
         return orientation;
     }
