app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java
public NearbyPlacesInfo loadAttractionsFromLocation(LatLng curLatLng) throws IOException {

        Timber.d("Loading attractions near %s", curLatLng);
        NearbyPlacesInfo nearbyPlacesInfo = new NearbyPlacesInfo();

        if (curLatLng == null) {
            return null;
        }
        List<Place> places = nearbyPlaces.getFromWikidataQuery(curLatLng, Locale.getDefault().getLanguage());

        if (null != places && 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) {
                    distances.put(place, computeDistanceBetween(place.location, curLatLng));
                    // Find boundaries with basic find max approach
                    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);
                        }
                );
            }
            nearbyPlacesInfo.placeList = places;
            nearbyPlacesInfo.boundaryCoordinates = boundaryCoordinates;
            return nearbyPlacesInfo;
        }
        else {
            return null;
        }
    }
/**
     * Prepares Place list to make their distance information update later.
     *
     * @param curLatLng current location for user
     * @return NearbyPlacesInfo a variable holds Place list without distance information
     * and boundary coordinates of current Place List
     */
Prepares Place list to make their distance information update later.
@param curLatLng current location for user
@return NearbyPlacesInfo a variable holds Place list without distance information
and boundary coordinates of current Place List
Prepares Place list to make their distance information update later . @param curLatLng current location for user @return NearbyPlacesInfo a variable holds Place list without distance information and boundary coordinates of current Place List
public NearbyPlacesInfo loadAttractionsFromLocation(LatLng curLatLng) throws IOException {
        Timber.d("Loading attractions near %s", curLatLng);
        NearbyPlacesInfo nearbyPlacesInfo = new NearbyPlacesInfo();
        if (curLatLng == null) {
            return null;
        }
        List<Place> places = nearbyPlaces.getFromWikidataQuery(curLatLng, Locale.getDefault().getLanguage());
        if (null != places && places.size() > 0) {
            LatLng[] boundaryCoordinates = {places.get(0).location,   
                    places.get(0).location, 
                    places.get(0).location, 
                    places.get(0).location};
            if (curLatLng != null) {
                Timber.d("Sorting places by distance...");
                final Map<Place, Double> distances = new HashMap<>();
                for (Place place : places) {
                    distances.put(place, computeDistanceBetween(place.location, curLatLng));
                    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);
                        }
                );
            }
            nearbyPlacesInfo.placeList = places;
            nearbyPlacesInfo.boundaryCoordinates = boundaryCoordinates;
            return nearbyPlacesInfo;
        }
        else {
            return null;
        }
    }
public NearbyPlacesInfo loadAttractionsFromLocation ( LatLng curLatLng ) throws IOException { Timber . d ( "Loading attractions near %s" , curLatLng ) ; NearbyPlacesInfo nearbyPlacesInfo = new NearbyPlacesInfo ( ) ; if ( curLatLng == null ) { return null ; } List < Place > places = nearbyPlaces . getFromWikidataQuery ( curLatLng , Locale . getDefault ( ) . getLanguage ( ) ) ; if ( null != places && places . size ( ) > 0 ) { LatLng [ ] boundaryCoordinates = { places . get ( 0 ) . location , places . get ( 0 ) . location , places . get ( 0 ) . location , places . get ( 0 ) . location } ; if ( curLatLng != null ) { Timber . d ( "Sorting places by distance..." ) ; final Map < Place , Double > distances = new HashMap < > ( ) ; for ( Place place : places ) { distances . put ( place , computeDistanceBetween ( place . location , curLatLng ) ) ; 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 ) ; } ) ; } nearbyPlacesInfo . placeList = places ; nearbyPlacesInfo . boundaryCoordinates = boundaryCoordinates ; return nearbyPlacesInfo ; } else { return null ; } }
Prepares Place list to make their distance information update later.
Prepares Place list to make their distance information update later .
// south // north // west // east, init with a random location // Find boundaries with basic find max approach