diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java index c7ad89e08..c140e024b 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java @@ -328,10 +328,20 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment nearbyParentFragmentInstanceReadyCallback.onReady(); } performMapReadyActions(); - final CameraPosition cameraPosition = new CameraPosition.Builder() + final CameraPosition cameraPosition; + if(applicationKvStore.getString("LastLocation")!=null) { // Checking for last searched location + String[] locationLatLng = applicationKvStore.getString("LastLocation").split(","); + cameraPosition = new CameraPosition.Builder() + .target(new LatLng(Double.valueOf(locationLatLng[0]), + Double.valueOf(locationLatLng[1]))) + .zoom(ZOOM_LEVEL) + .build(); + }else { + cameraPosition = new CameraPosition.Builder() .target(new LatLng(51.50550, -0.07520)) .zoom(ZOOM_OUT) .build(); + } mapBoxMap.setCameraPosition(cameraPosition); final ScaleBarPlugin scaleBarPlugin = new ScaleBarPlugin(mapView, mapBoxMap); @@ -345,6 +355,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment .setMarginLeft(R.dimen.tiny_padding) .setTextBarMargin(R.dimen.tiny_padding); scaleBarPlugin.create(scaleBarOptions); + onResume(); }); }); @@ -485,17 +496,27 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment mapView.onStart(); applicationKvStore.putBoolean("doNotAskForLocationPermission", true); - lastKnownLocation = new fr.free.nrw.commons.location.LatLng(51.50550,-0.07520,1f); - final CameraPosition position = new CameraPosition.Builder() - .target(LocationUtils.commonsLatLngToMapBoxLatLng(lastKnownLocation)) - .zoom(ZOOM_OUT) - .build(); + final CameraPosition position; + if(applicationKvStore.getString("LastLocation")!=null) { // Checking for last searched location + String[] locationLatLng = applicationKvStore.getString("LastLocation").split(","); + lastKnownLocation = new fr.free.nrw.commons.location.LatLng(Double.valueOf(locationLatLng[0]), Double.valueOf(locationLatLng[1]), 1f); + position = new CameraPosition.Builder() + .target(LocationUtils.commonsLatLngToMapBoxLatLng(lastKnownLocation)) + .zoom(ZOOM_LEVEL) + .build(); + }else { + lastKnownLocation = new fr.free.nrw.commons.location.LatLng(51.50550,-0.07520,1f); + position = new CameraPosition.Builder() + .target(LocationUtils.commonsLatLngToMapBoxLatLng(lastKnownLocation)) + .zoom(ZOOM_OUT) + .build(); + } if(mapBox != null){ mapBox.moveCamera(CameraUpdateFactory.newCameraPosition(position)); addOnCameraMoveListener(); + presenter.onMapReady(); + removeCurrentLocationMarker(); } - presenter.onMapReady(); - removeCurrentLocationMarker(); } private void registerNetworkReceiver() { @@ -1076,6 +1097,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment if (nearbyPlacesInfo.placeList == null || nearbyPlacesInfo.placeList.isEmpty()) { showErrorMessage(getString(R.string.no_nearby_places_around)); } else { + // Updating last searched location + applicationKvStore.putString("LastLocation", searchLatLng.getLatitude() + "," + searchLatLng.getLongitude()); updateMapMarkers(nearbyPlacesInfo, false); lastFocusLocation = searchLatLng; }