Skip to content

Commit 22b6ce5

Browse files
authored
Merge pull request commons-app#226 from misaochan/fix-gps-extractor
Fix recent GPSExtractor crash
2 parents fb5eb34 + 8b23bb0 commit 22b6ce5

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

app/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.media.ExifInterface;
1010
import android.os.Bundle;
1111
import android.preference.PreferenceManager;
12+
import android.support.annotation.Nullable;
1213
import android.support.design.widget.Snackbar;
1314
import android.util.Log;
1415
import java.io.IOException;
@@ -82,6 +83,7 @@ protected void unregisterLocationManager() {
8283
* Extracts geolocation of image from EXIF data.
8384
* @return coordinates of image as string (needs to be passed as a String in API query)
8485
*/
86+
@Nullable
8587
public String getCoords(boolean useGPS) {
8688

8789
ExifInterface exif;
@@ -117,7 +119,7 @@ public String getCoords(boolean useGPS) {
117119
// No coords found
118120
return null;
119121
}
120-
} else if(exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE) == null) {
122+
} else if (exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE) == null) {
121123
return null;
122124
} else {
123125
imageCoordsExists = true;
@@ -127,11 +129,16 @@ public String getCoords(boolean useGPS) {
127129
latitude_ref = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
128130
longitude = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
129131
longitude_ref = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);
130-
Log.d("Image", "Latitude: " + latitude + " " + latitude_ref);
131-
Log.d("Image", "Longitude: " + longitude + " " + longitude_ref);
132132

133-
decimalCoords = getDecimalCoords(latitude, latitude_ref, longitude, longitude_ref);
134-
return decimalCoords;
133+
if (latitude!=null && latitude_ref!=null && longitude!=null && longitude_ref!=null) {
134+
Log.d("Image", "Latitude: " + latitude + " " + latitude_ref);
135+
Log.d("Image", "Longitude: " + longitude + " " + longitude_ref);
136+
137+
decimalCoords = getDecimalCoords(latitude, latitude_ref, longitude, longitude_ref);
138+
return decimalCoords;
139+
} else {
140+
return null;
141+
}
135142
}
136143
}
137144

0 commit comments

Comments
 (0)