I am developing the nearest Food Dish application location. I managed to display it based on the location closest to the user, using this plugin great_circle_distance
I want to know how to set the max radius? ex. < 30 Km
Here my code:
_foodByCategories.sort((a, b) {
var distance1 = new GreatCircleDistance.fromDegrees(
latitude1:
model.userLocation == null ? 0.0 : model.userLocation["latitude"],
longitude1: model.userLocation == null
? 0.0
: model.userLocation["longitude"],
latitude2: a.lat,
longitude2: a.long);
double totaldistance1 = distance1.haversineDistance();
var distance2 = new GreatCircleDistance.fromDegrees(
latitude1:
model.userLocation == null ? 0.0 : model.userLocation["latitude"],
longitude1: model.userLocation == null
? 0.0
: model.userLocation["longitude"],
latitude2: b.lat,
longitude2: b.long);
double totaldistance2 = distance2.haversineDistance();
return (totaldistance1 - totaldistance2).toInt();
});
Any answer will appreciated.
I can't see any way to do this within the package you are using. You could suggest to the developer to add this functionality in?
Alternatively, you are getting the
total distance
in your code so you could just do a simpleif statement
to check if the total distance is greater than your set max radius.If I understand your question correct