@@ -29,6 +29,7 @@ public class NearbyPlaces {
2929 private static final Uri WIKIDATA_QUERY_URL = Uri .parse ("https://query.wikidata.org/sparql" );
3030 private static final Uri WIKIDATA_QUERY_UI_URL = Uri .parse ("https://query.wikidata.org/" );
3131 private final String wikidataQuery ;
32+ private double radius = INITIAL_RADIUS ;
3233 private List <Place > places ;
3334
3435 public NearbyPlaces () {
@@ -42,11 +43,10 @@ public NearbyPlaces() {
4243
4344 List <Place > getFromWikidataQuery (LatLng curLatLng , String lang ) {
4445 List <Place > places = Collections .emptyList ();
45- double radius = INITIAL_RADIUS ;
4646
4747 try {
4848 // increase the radius gradually to find a satisfactory number of nearby places
49- while (radius < MAX_RADIUS ) {
49+ while (radius <= MAX_RADIUS ) {
5050 places = getFromWikidataQuery (curLatLng , lang , radius );
5151 Timber .d ("%d results at radius: %f" , places .size (), radius );
5252 if (places .size () >= MIN_RESULTS ) {
@@ -60,7 +60,13 @@ List<Place> getFromWikidataQuery(LatLng curLatLng, String lang) {
6060 // errors tend to be caused by too many results (and time out)
6161 // try a small radius next time
6262 Timber .d ("back to initial radius: %f" , radius );
63+ radius = INITIAL_RADIUS ;
6364 }
65+ // make sure we will be able to send at least one request next time
66+ if (radius > MAX_RADIUS ) {
67+ radius = MAX_RADIUS ;
68+ }
69+
6470 return places ;
6571 }
6672
0 commit comments