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.
This commit is contained in:
Jason Whitmore 2024-07-05 16:05:47 -07:00
parent d941c2fa8e
commit 442ab08711

View file

@ -45,6 +45,7 @@ import fr.free.nrw.commons.coordinates.CoordinateEditHelper;
import fr.free.nrw.commons.filepicker.Constants; import fr.free.nrw.commons.filepicker.Constants;
import fr.free.nrw.commons.kvstore.BasicKvStore; import fr.free.nrw.commons.kvstore.BasicKvStore;
import fr.free.nrw.commons.kvstore.JsonKvStore; 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;
import fr.free.nrw.commons.location.LocationPermissionsHelper.LocationPermissionCallback; import fr.free.nrw.commons.location.LocationPermissionsHelper.LocationPermissionCallback;
import fr.free.nrw.commons.location.LocationServiceManager; import fr.free.nrw.commons.location.LocationServiceManager;
@ -328,7 +329,6 @@ public class LocationPickerActivity extends BaseActivity implements
private void setupMapView() { private void setupMapView() {
requestLocationPermissions(); requestLocationPermissions();
moveMapToMediaLocation();
modifyLocationButton.setOnClickListener(v -> onClickModifyLocation()); modifyLocationButton.setOnClickListener(v -> onClickModifyLocation());
removeLocationButton.setOnClickListener(v -> onClickRemoveLocation()); removeLocationButton.setOnClickListener(v -> onClickRemoveLocation());
showInMapButton.setOnClickListener(v -> showInMapApp()); 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 * Select the preferable location
*/ */