New registerLocationUpdates() function

This commit is contained in:
misaochan 2016-02-08 15:32:06 +13:00
parent 565e60f666
commit e5b746e411

View file

@ -22,6 +22,9 @@ public class GPSExtractor {
private Context context;
public boolean imageCoordsExists;
private MyLocationListener myLocationListener;
private LocationManager locationManager;
private String provider;
private Criteria criteria;
public GPSExtractor(String filePath, Context context){
this.filePath = filePath;
@ -35,6 +38,15 @@ public class GPSExtractor {
return gpsPref;
}
private void registerLocationManager() {
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, true);
myLocationListener = new MyLocationListener();
locationManager.requestLocationUpdates(provider, 400, 1, myLocationListener);
}
//Extract GPS coords of image
public String getCoords() {
@ -60,13 +72,7 @@ public class GPSExtractor {
boolean gpsPrefEnabled = gpsPreferenceEnabled();
if (gpsPrefEnabled) {
//If pref enabled, set up LocationListener to get current location
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
myLocationListener = new MyLocationListener();
locationManager.requestLocationUpdates(provider, 400, 1, myLocationListener);
//If pref enabled, get current location
Location location = locationManager.getLastKnownLocation(provider);
if (location != null) {