From fc41235d5fec66dabdc27b44d6ba522dafa3dbd8 Mon Sep 17 00:00:00 2001 From: neslihanturan Date: Tue, 18 Sep 2018 14:03:58 +0300 Subject: [PATCH] Modify getFromWikidataQuery method, so that based on the restunClosestResult boolean, we get only the closest nearby place, instead of fetching bunch of nearby places each time --- .../fr/free/nrw/commons/nearby/NearbyPlaces.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyPlaces.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyPlaces.java index f9d35d63e..0c27c1331 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyPlaces.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyPlaces.java @@ -23,9 +23,9 @@ import timber.log.Timber; public class NearbyPlaces { - private static final int MIN_RESULTS = 40; + private static int MIN_RESULTS = 40; private static final double INITIAL_RADIUS = 1.0; // in kilometers - private static final double MAX_RADIUS = 300.0; // in kilometers + private static double MAX_RADIUS = 300.0; // in kilometers private static final double RADIUS_MULTIPLIER = 1.618; private static final Uri WIKIDATA_QUERY_URL = Uri.parse("https://query.wikidata.org/sparql"); private static final Uri WIKIDATA_QUERY_UI_URL = Uri.parse("https://query.wikidata.org/"); @@ -41,9 +41,18 @@ public class NearbyPlaces { } } - List getFromWikidataQuery(LatLng curLatLng, String lang) throws IOException { + List getFromWikidataQuery(LatLng curLatLng, String lang, boolean returnClosestResult) throws IOException { List places = Collections.emptyList(); + /** + * If returnClosestResult is true, then this means that we are trying to get closest point + * to use in cardView above contributions list + */ + if (returnClosestResult) { + MIN_RESULTS = 1; // Return closest nearby place + MAX_RADIUS = 5; // Return places only in 5 km area + } + // increase the radius gradually to find a satisfactory number of nearby places while (radius <= MAX_RADIUS) { try { @@ -143,4 +152,5 @@ public class NearbyPlaces { return places; } + }