mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Merge remote-tracking branch 'refs/remotes/origin/2.7.x-release'
This commit is contained in:
commit
a927a80265
1 changed files with 38 additions and 32 deletions
|
|
@ -54,41 +54,47 @@ public class NearbyController {
|
||||||
}
|
}
|
||||||
List<Place> places = nearbyPlaces.getFromWikidataQuery(curLatLng, Locale.getDefault().getLanguage());
|
List<Place> places = nearbyPlaces.getFromWikidataQuery(curLatLng, Locale.getDefault().getLanguage());
|
||||||
|
|
||||||
LatLng[] boundaryCoordinates = {places.get(0).location, // south
|
if (places.size() > 0) {
|
||||||
places.get(0).location, // north
|
LatLng[] boundaryCoordinates = {places.get(0).location, // south
|
||||||
places.get(0).location, // west
|
places.get(0).location, // north
|
||||||
places.get(0).location};// east, init with a random location
|
places.get(0).location, // west
|
||||||
|
places.get(0).location};// east, init with a random location
|
||||||
|
|
||||||
if (curLatLng != null) {
|
|
||||||
Timber.d("Sorting places by distance...");
|
if (curLatLng != null) {
|
||||||
final Map<Place, Double> distances = new HashMap<>();
|
Timber.d("Sorting places by distance...");
|
||||||
for (Place place: places) {
|
final Map<Place, Double> distances = new HashMap<>();
|
||||||
distances.put(place, computeDistanceBetween(place.location, curLatLng));
|
for (Place place : places) {
|
||||||
// Find boundaries with basic find max approach
|
distances.put(place, computeDistanceBetween(place.location, curLatLng));
|
||||||
if (place.location.getLatitude() < boundaryCoordinates[0].getLatitude()) {
|
// Find boundaries with basic find max approach
|
||||||
boundaryCoordinates[0] = place.location;
|
if (place.location.getLatitude() < boundaryCoordinates[0].getLatitude()) {
|
||||||
}
|
boundaryCoordinates[0] = place.location;
|
||||||
if (place.location.getLatitude() > boundaryCoordinates[1].getLatitude()) {
|
|
||||||
boundaryCoordinates[1] = place.location;
|
|
||||||
}
|
|
||||||
if (place.location.getLongitude() < boundaryCoordinates[2].getLongitude()) {
|
|
||||||
boundaryCoordinates[2] = place.location;
|
|
||||||
}
|
|
||||||
if (place.location.getLongitude() > boundaryCoordinates[3].getLongitude()) {
|
|
||||||
boundaryCoordinates[3] = place.location;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Collections.sort(places,
|
|
||||||
(lhs, rhs) -> {
|
|
||||||
double lhsDistance = distances.get(lhs);
|
|
||||||
double rhsDistance = distances.get(rhs);
|
|
||||||
return (int) (lhsDistance - rhsDistance);
|
|
||||||
}
|
}
|
||||||
);
|
if (place.location.getLatitude() > boundaryCoordinates[1].getLatitude()) {
|
||||||
|
boundaryCoordinates[1] = place.location;
|
||||||
|
}
|
||||||
|
if (place.location.getLongitude() < boundaryCoordinates[2].getLongitude()) {
|
||||||
|
boundaryCoordinates[2] = place.location;
|
||||||
|
}
|
||||||
|
if (place.location.getLongitude() > boundaryCoordinates[3].getLongitude()) {
|
||||||
|
boundaryCoordinates[3] = place.location;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Collections.sort(places,
|
||||||
|
(lhs, rhs) -> {
|
||||||
|
double lhsDistance = distances.get(lhs);
|
||||||
|
double rhsDistance = distances.get(rhs);
|
||||||
|
return (int) (lhsDistance - rhsDistance);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
nearbyPlacesInfo.placeList = places;
|
||||||
|
nearbyPlacesInfo.boundaryCoordinates = boundaryCoordinates;
|
||||||
|
return nearbyPlacesInfo;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
nearbyPlacesInfo.placeList = places;
|
|
||||||
nearbyPlacesInfo.boundaryCoordinates = boundaryCoordinates;
|
|
||||||
return nearbyPlacesInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue