mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Fixes #4571 - Nearby: Save last known location and show it immediately without waiting for GPS (#4721)
* save last location feature * fix lat lng exchange * removed unnecessary space Co-authored-by: Pratham2305 <Pratham2305@users.noreply.github.com>
This commit is contained in:
parent
8a2c30120d
commit
8a0d5580b2
1 changed files with 31 additions and 8 deletions
|
|
@ -328,10 +328,20 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
nearbyParentFragmentInstanceReadyCallback.onReady();
|
nearbyParentFragmentInstanceReadyCallback.onReady();
|
||||||
}
|
}
|
||||||
performMapReadyActions();
|
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))
|
.target(new LatLng(51.50550, -0.07520))
|
||||||
.zoom(ZOOM_OUT)
|
.zoom(ZOOM_OUT)
|
||||||
.build();
|
.build();
|
||||||
|
}
|
||||||
mapBoxMap.setCameraPosition(cameraPosition);
|
mapBoxMap.setCameraPosition(cameraPosition);
|
||||||
|
|
||||||
final ScaleBarPlugin scaleBarPlugin = new ScaleBarPlugin(mapView, mapBoxMap);
|
final ScaleBarPlugin scaleBarPlugin = new ScaleBarPlugin(mapView, mapBoxMap);
|
||||||
|
|
@ -345,6 +355,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
.setMarginLeft(R.dimen.tiny_padding)
|
.setMarginLeft(R.dimen.tiny_padding)
|
||||||
.setTextBarMargin(R.dimen.tiny_padding);
|
.setTextBarMargin(R.dimen.tiny_padding);
|
||||||
scaleBarPlugin.create(scaleBarOptions);
|
scaleBarPlugin.create(scaleBarOptions);
|
||||||
|
onResume();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -485,18 +496,28 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
mapView.onStart();
|
mapView.onStart();
|
||||||
|
|
||||||
applicationKvStore.putBoolean("doNotAskForLocationPermission", true);
|
applicationKvStore.putBoolean("doNotAskForLocationPermission", true);
|
||||||
|
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);
|
lastKnownLocation = new fr.free.nrw.commons.location.LatLng(51.50550,-0.07520,1f);
|
||||||
final CameraPosition position = new CameraPosition.Builder()
|
position = new CameraPosition.Builder()
|
||||||
.target(LocationUtils.commonsLatLngToMapBoxLatLng(lastKnownLocation))
|
.target(LocationUtils.commonsLatLngToMapBoxLatLng(lastKnownLocation))
|
||||||
.zoom(ZOOM_OUT)
|
.zoom(ZOOM_OUT)
|
||||||
.build();
|
.build();
|
||||||
|
}
|
||||||
if(mapBox != null){
|
if(mapBox != null){
|
||||||
mapBox.moveCamera(CameraUpdateFactory.newCameraPosition(position));
|
mapBox.moveCamera(CameraUpdateFactory.newCameraPosition(position));
|
||||||
addOnCameraMoveListener();
|
addOnCameraMoveListener();
|
||||||
}
|
|
||||||
presenter.onMapReady();
|
presenter.onMapReady();
|
||||||
removeCurrentLocationMarker();
|
removeCurrentLocationMarker();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void registerNetworkReceiver() {
|
private void registerNetworkReceiver() {
|
||||||
if (getActivity() != null) {
|
if (getActivity() != null) {
|
||||||
|
|
@ -1076,6 +1097,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
if (nearbyPlacesInfo.placeList == null || nearbyPlacesInfo.placeList.isEmpty()) {
|
if (nearbyPlacesInfo.placeList == null || nearbyPlacesInfo.placeList.isEmpty()) {
|
||||||
showErrorMessage(getString(R.string.no_nearby_places_around));
|
showErrorMessage(getString(R.string.no_nearby_places_around));
|
||||||
} else {
|
} else {
|
||||||
|
// Updating last searched location
|
||||||
|
applicationKvStore.putString("LastLocation", searchLatLng.getLatitude() + "," + searchLatLng.getLongitude());
|
||||||
updateMapMarkers(nearbyPlacesInfo, false);
|
updateMapMarkers(nearbyPlacesInfo, false);
|
||||||
lastFocusLocation = searchLatLng;
|
lastFocusLocation = searchLatLng;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue