From dd4e7c3aa07f78a02fef1853a6e338f11ce7038b Mon Sep 17 00:00:00 2001 From: Sergey Kozelko Date: Fri, 27 Oct 2017 14:15:25 +0300 Subject: [PATCH 1/2] Fixed bug when there are places nearby but none are loaded --- app/src/main/java/fr/free/nrw/commons/nearby/NearbyPlaces.java | 3 +-- 1 file changed, 1 insertion(+), 2 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 50d661ef6..122042eff 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 @@ -29,7 +29,6 @@ public class NearbyPlaces { 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/"); private final String wikidataQuery; - private double radius = INITIAL_RADIUS; private List places; public NearbyPlaces() { @@ -43,6 +42,7 @@ public class NearbyPlaces { List getFromWikidataQuery(LatLng curLatLng, String lang) { List places = Collections.emptyList(); + double radius = INITIAL_RADIUS; try { // increase the radius gradually to find a satisfactory number of nearby places @@ -60,7 +60,6 @@ public class NearbyPlaces { // errors tend to be caused by too many results (and time out) // try a small radius next time Timber.d("back to initial radius: %f", radius); - radius = INITIAL_RADIUS; } return places; } From bd5b95040dd97d9f30b1fbc2869ef739d4f2f4b5 Mon Sep 17 00:00:00 2001 From: Sergey Kozelko Date: Fri, 27 Oct 2017 20:02:39 +0300 Subject: [PATCH 2/2] Force request radius to be no larger than MAX_RADIUS, thus always make request --- .../java/fr/free/nrw/commons/nearby/NearbyPlaces.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 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 122042eff..de14a2ef8 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 @@ -29,6 +29,7 @@ public class NearbyPlaces { 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/"); private final String wikidataQuery; + private double radius = INITIAL_RADIUS; private List places; public NearbyPlaces() { @@ -42,11 +43,10 @@ public class NearbyPlaces { List getFromWikidataQuery(LatLng curLatLng, String lang) { List places = Collections.emptyList(); - double radius = INITIAL_RADIUS; try { // increase the radius gradually to find a satisfactory number of nearby places - while (radius < MAX_RADIUS) { + while (radius <= MAX_RADIUS) { places = getFromWikidataQuery(curLatLng, lang, radius); Timber.d("%d results at radius: %f", places.size(), radius); if (places.size() >= MIN_RESULTS) { @@ -60,7 +60,13 @@ public class NearbyPlaces { // errors tend to be caused by too many results (and time out) // try a small radius next time Timber.d("back to initial radius: %f", radius); + radius = INITIAL_RADIUS; } + // make sure we will be able to send at least one request next time + if (radius > MAX_RADIUS) { + radius = MAX_RADIUS; + } + return places; }