Skip to content

Commit

Permalink
Merge pull request #48 from IliyanIlievPH/master
Browse files Browse the repository at this point in the history
Add location limit and bigger default radius value
  • Loading branch information
starkmsu committed May 29, 2020
2 parents e183720 + 2dfa33b commit 4213474
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public async Task<Guid[]> GetNearPartnerIdsAsync(double? radiusInKm, double? lon
throw new ArgumentException("Invalid argument value for get near partners request");

var searchByCoordinates = latitude.HasValue && longitude.HasValue;
radiusInKm = radiusInKm ?? 1;
radiusInKm = radiusInKm ?? 8;

var locations = searchByCoordinates
? await GetLocationsByCoordinates(latitude.Value, longitude.Value, radiusInKm.Value, iso3Code)
Expand All @@ -257,8 +257,9 @@ public async Task<Guid[]> GetNearPartnerIdsAsync(double? radiusInKm, double? lon
private async Task<IEnumerable<Location>> GetLocationsByCoordinates(double latitude, double longitude, double radiusInKm, string iso3Code)
{
string geohash = null;
var hasAnyLocations = false;
var locationsCount = 0;
IEnumerable<Location> locations = null;
const int locationsLimit = 20;
//Try to get locations in radius if there are not locations in this radius,
//increase it and try again until you find location or the radius exceeds the maximum allowed
do
Expand Down Expand Up @@ -287,10 +288,10 @@ private async Task<IEnumerable<Location>> GetLocationsByCoordinates(double latit
.OrderBy(l => locationDistances[l.Id]);
}

hasAnyLocations = locations.Any();
locationsCount = locations.Count();
radiusInKm *= 2;

} while (radiusInKm <= MaxRadiusInKm && !hasAnyLocations);
} while (radiusInKm <= MaxRadiusInKm && locationsCount < locationsLimit);

return locations;
}
Expand Down

0 comments on commit 4213474

Please sign in to comment.