-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
feat(mobile): sort places by distance #17740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Not sure if this is an enhancement or a feature, feel free to change it :) |
places.sort((a, b) { | ||
final double distanceA = calculateDistance( | ||
currentLocation!.latitude, | ||
currentLocation!.longitude, | ||
a.latitude, | ||
a.longitude, | ||
); | ||
final double distanceB = calculateDistance( | ||
currentLocation!.latitude, | ||
currentLocation!.longitude, | ||
b.latitude, | ||
b.longitude, | ||
); | ||
|
||
return isAscending.value | ||
? distanceA.compareTo(distanceB) | ||
: distanceB.compareTo(distanceA); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This kind of thing is usually indexed. Can you test how long it takes to brute force it like this with maybe 5000 places?
return isAscending.value | ||
? distanceA.compareTo(distanceB) | ||
: distanceB.compareTo(distanceA); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's generally better to move this outside of the inner sort function and have separate variants to keep the sort function branchless.
} else { | ||
// Sort places by name | ||
places.sort( | ||
(a, b) => isAscending.value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
latitude: data.exifInfo!.latitude!.toDouble(), | ||
longitude: data.exifInfo!.longitude!.toDouble(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this actually safe? These values can be null.
Currently blocked by #17882
Description
Added the ability to sort the places by distance (from nearest to furthest) from the user's location.
How Has This Been Tested?
Screenshot