From e5b746e411e80ffe147a54752675bfe98265603b Mon Sep 17 00:00:00 2001 From: misaochan Date: Mon, 8 Feb 2016 15:32:06 +1300 Subject: [PATCH] New registerLocationUpdates() function --- .../free/nrw/commons/upload/GPSExtractor.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java b/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java index 7c3bf1da4..3db6460ec 100644 --- a/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java +++ b/commons/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java @@ -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) {