mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Add null check
This commit is contained in:
parent
fb5eb3465e
commit
8b23bb04f4
1 changed files with 12 additions and 5 deletions
|
|
@ -9,6 +9,7 @@ import android.location.LocationManager;
|
||||||
import android.media.ExifInterface;
|
import android.media.ExifInterface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
@ -82,6 +83,7 @@ public class GPSExtractor {
|
||||||
* Extracts geolocation of image from EXIF data.
|
* Extracts geolocation of image from EXIF data.
|
||||||
* @return coordinates of image as string (needs to be passed as a String in API query)
|
* @return coordinates of image as string (needs to be passed as a String in API query)
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getCoords(boolean useGPS) {
|
public String getCoords(boolean useGPS) {
|
||||||
|
|
||||||
ExifInterface exif;
|
ExifInterface exif;
|
||||||
|
|
@ -127,11 +129,16 @@ public class GPSExtractor {
|
||||||
latitude_ref = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
|
latitude_ref = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
|
||||||
longitude = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
|
longitude = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
|
||||||
longitude_ref = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);
|
longitude_ref = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);
|
||||||
|
|
||||||
|
if (latitude!=null && latitude_ref!=null && longitude!=null && longitude_ref!=null) {
|
||||||
Log.d("Image", "Latitude: " + latitude + " " + latitude_ref);
|
Log.d("Image", "Latitude: " + latitude + " " + latitude_ref);
|
||||||
Log.d("Image", "Longitude: " + longitude + " " + longitude_ref);
|
Log.d("Image", "Longitude: " + longitude + " " + longitude_ref);
|
||||||
|
|
||||||
decimalCoords = getDecimalCoords(latitude, latitude_ref, longitude, longitude_ref);
|
decimalCoords = getDecimalCoords(latitude, latitude_ref, longitude, longitude_ref);
|
||||||
return decimalCoords;
|
return decimalCoords;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue