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

This commit is contained in:
neslihanturan 2018-09-18 14:03:58 +03:00
parent 829256195b
commit fc41235d5f

View file

@ -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<Place> getFromWikidataQuery(LatLng curLatLng, String lang) throws IOException {
List<Place> getFromWikidataQuery(LatLng curLatLng, String lang, boolean returnClosestResult) throws IOException {
List<Place> 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;
}
}