mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
If else block for gps prefs
This commit is contained in:
parent
5492aa7551
commit
11e291cb41
1 changed files with 19 additions and 14 deletions
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue