If else block for gps prefs

This commit is contained in:
misaochan 2016-02-05 18:31:46 +13:00
parent 5492aa7551
commit 11e291cb41

View file

@ -65,24 +65,29 @@ public class GPSExtractor {
//Check what user's preference is for automatic location detection //Check what user's preference is for automatic location detection
boolean gpsPrefEnabled = gpsPreferenceEnabled(); boolean gpsPrefEnabled = gpsPreferenceEnabled();
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); if (gpsPrefEnabled) {
Criteria criteria = new Criteria(); //If pref enabled, set up LocationListener to get current location
String provider = locationManager.getBestProvider(criteria, true); LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
myLocationListener = new MyLocationListener(); myLocationListener = new MyLocationListener();
locationManager.requestLocationUpdates(provider, 400, 1, myLocationListener); locationManager.requestLocationUpdates(provider, 400, 1, myLocationListener);
Location location = locationManager.getLastKnownLocation(provider); Location location = locationManager.getLastKnownLocation(provider);
if (location != null) { if (location != null) {
myLocationListener.onLocationChanged(location); myLocationListener.onLocationChanged(location);
} } else {
else { //calling method is equipped to deal with null return value
//calling method is equipped to deal with null return value return null;
}
Log.d(TAG, "Current location values: Lat = " + currentLatitude + " Long = " + currentLongitude);
String currentCoords = String.valueOf(currentLatitude) + "|" + String.valueOf(currentLongitude);
return currentCoords;
} else {
//Otherwise treat as if no coords found
return null; return null;
} }
Log.d(TAG, "Current location values: Lat = " + currentLatitude + " Long = " + currentLongitude);
String currentCoords = String.valueOf(currentLatitude) + "|" + String.valueOf(currentLongitude);
return currentCoords;
} else { } else {
imageCoordsExists = true; imageCoordsExists = true;