tomoakley / freemeals.uk

MIT License
10 stars 10 forks source link

feat: fetch user coords and sort results by nearest location first #17

Closed kurt-culley closed 3 years ago

kurt-culley commented 3 years ago

Hey here's my initial attempt at helping fix https://github.com/tomoakley/freemeals.uk/issues/4 I've noticed some of the coordinates aren't correct/valid, but it still seems to work quite well! I think the app could possibly do with some work around toggling the 'Getting list of fantastic providers...' loading screen, as currently when the user accepts having their geo data shared, it takes a second or two and then 'pops' in which isn't great UX imo

tomoakley commented 3 years ago

Hey Kurt, thanks! I was actually working on this too but no worries 👍

Couple of things: To get the coords I used https://www.npmjs.com/package/react-geolocated, which worked well. If you're happy staying with the raw Geolocation API, that's fine I did the filtering on the lambda function, by passing the coords to it and using https://github.com/darkskyapp/sphere-knn to find the closest results. I think personally this is a better way of doing it (better to do intensive tasks server side, imo), but it's up to you. Given that I assume you got this working, I'm happy to merge it

19 has just been merged, can you pull that in to your fork and fix the conflicts? Thanks

tomoakley commented 3 years ago

@kurt-culley we need postcode lookup too (not in this PR) - I think it might make sense to do the sorting/filtering by geocoords on the lambda? that way, we can convert the postcode to coordinates on the frontend, then send it to the lambda in the same way we could send the coordinates obtained from the Geolocation API

Just pushed my branch, https://github.com/tomoakley/freemeals.uk/compare/geolocation-filtering if you want to take a look at my approach

kurt-culley commented 3 years ago

Apologies, I should've asked on the issue first! 🙂

To get the coords I used https://www.npmjs.com/package/react-geolocated, which worked well.

I actually quite like the look of that package, I'll have a go at using that instead of the raw API

I did the filtering on the lambda function

I agree this is definitely the better way of doing it. I'll take a look at your branch!

19 has just been merged, can you pull that in to your fork and fix the conflicts?

Will do 👍