mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Merge pull request #1385 from misaochan/fix-index-error
Fix IndexOutOfBounds exception in Nearby
This commit is contained in:
commit
286581dd8f
1 changed files with 38 additions and 32 deletions
|
|
@ -54,15 +54,17 @@ public class NearbyController {
|
|||
}
|
||||
List<Place> places = nearbyPlaces.getFromWikidataQuery(curLatLng, Locale.getDefault().getLanguage());
|
||||
|
||||
if (places.size() > 0) {
|
||||
LatLng[] boundaryCoordinates = {places.get(0).location, // south
|
||||
places.get(0).location, // north
|
||||
places.get(0).location, // west
|
||||
places.get(0).location};// east, init with a random location
|
||||
|
||||
|
||||
if (curLatLng != null) {
|
||||
Timber.d("Sorting places by distance...");
|
||||
final Map<Place, Double> distances = new HashMap<>();
|
||||
for (Place place: places) {
|
||||
for (Place place : places) {
|
||||
distances.put(place, computeDistanceBetween(place.location, curLatLng));
|
||||
// Find boundaries with basic find max approach
|
||||
if (place.location.getLatitude() < boundaryCoordinates[0].getLatitude()) {
|
||||
|
|
@ -90,6 +92,10 @@ public class NearbyController {
|
|||
nearbyPlacesInfo.boundaryCoordinates = boundaryCoordinates;
|
||||
return nearbyPlacesInfo;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads attractions from location for list view, we need to return Place data type.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue