From f68939975de2bb63246f8246b6df2437ebeb3fd2 Mon Sep 17 00:00:00 2001 From: Jason Whitmore Date: Tue, 28 May 2024 17:52:44 -0700 Subject: [PATCH] LocationPickerActivity.java: add methods to easily move the map center Before this change, any time the map center had to move, several lines of code had to be written. This change creates several methods which move the map center to a specified location. By using these new methods, moving the map center only takes one simple method call. --- .../LocationPickerActivity.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) 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 bc4c05222..434f6574e 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 @@ -249,6 +249,40 @@ public class LocationPickerActivity extends BaseActivity implements } } + /** + * Moves the center of the map to the specified coordinates + * + */ + private void moveMapTo(double latitude, double longitude){ + if(mapView != null && mapView.getController() != null){ + GeoPoint point = new GeoPoint(latitude, longitude); + + mapView.getController().setCenter(point); + mapView.getController().animateTo(point); + } + } + + /** + * Moves the center of the map to the specified coordinates + * @param point The GeoPoint object which contains the coordinates to move to + */ + private void moveMapTo(GeoPoint point){ + moveMapTo(point.getLatitude(), point.getLongitude()); + } + + /** + * Moves the center of the map to the media's location (likely EXIF data), if that data + * is available. + */ + private void moveMapToMediaLocation(){ + if(cameraPosition != null){ + double latitude = cameraPosition.getLatitude(); + double longitude = cameraPosition.getLongitude(); + + moveMapTo(latitude, longitude); + } + } + /** * For showing credits */