99import android .media .ExifInterface ;
1010import android .os .Bundle ;
1111import android .preference .PreferenceManager ;
12+ import android .support .annotation .Nullable ;
1213import android .support .design .widget .Snackbar ;
1314import android .util .Log ;
1415import 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