From 442ab0871141045cf5e768e77e47aa93db5f453d Mon Sep 17 00:00:00 2001 From: Jason Whitmore Date: Fri, 5 Jul 2024 16:05:47 -0700 Subject: [PATCH] LocationPickerActivity.java: create method to move location picker map to device GPS location Before this method was created, several lines of code were required to move the location picker map to the device's GPS location. After this method was created, the location picker map can be moved to the GPS location in a single method call. --- .../LocationPicker/LocationPickerActivity.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerActivity.java b/app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerActivity.java index 1b8a5f043..54c90edcc 100644 --- a/app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerActivity.java @@ -45,6 +45,7 @@ import fr.free.nrw.commons.coordinates.CoordinateEditHelper; import fr.free.nrw.commons.filepicker.Constants; import fr.free.nrw.commons.kvstore.BasicKvStore; import fr.free.nrw.commons.kvstore.JsonKvStore; +import fr.free.nrw.commons.location.LatLng; import fr.free.nrw.commons.location.LocationPermissionsHelper; import fr.free.nrw.commons.location.LocationPermissionsHelper.LocationPermissionCallback; import fr.free.nrw.commons.location.LocationServiceManager; @@ -328,7 +329,6 @@ public class LocationPickerActivity extends BaseActivity implements private void setupMapView() { requestLocationPermissions(); - moveMapToMediaLocation(); modifyLocationButton.setOnClickListener(v -> onClickModifyLocation()); removeLocationButton.setOnClickListener(v -> onClickRemoveLocation()); showInMapButton.setOnClickListener(v -> showInMapApp()); @@ -417,6 +417,21 @@ public class LocationPickerActivity extends BaseActivity implements } } + /** + * Moves the center of the map to the device's GPS location, if that data is available. + */ + private void moveMapToGPSLocation(){ + if(locationManager != null){ + fr.free.nrw.commons.location.LatLng location = locationManager.getLastLocation(); + + if(location != null){ + GeoPoint point = new GeoPoint(location.getLatitude(), location.getLongitude()); + + moveMapTo(point); + } + } + } + /** * Select the preferable location */