Open franzwollang opened 1 year ago
@ReallyBoard123
You can use this library for the distance calculations: https://github.com/manuelbieh/geolib It has a very convenient function called "isPointWithinRadius".
Although, this answer looks like the most comprehensive AND efficient solution: https://stackoverflow.com/a/45950426
I can help you write a port of the code to TypeScript, and help you use raw SQL queries inside of Prisma.
Modify it from just being based on matching interests to also include location as a search.
Use can use PRISMA "where" clauses to constrain the results to only those that: some_lat < lat < other_lat AND some_long < long < other_long
Calculate desired distance in 1) units of LONG and 2) units of LAT. Use these values from your center point (location) to create a bounding box. Use the bounding box to query users from PRISMA.
Then, before you return the results, filter over the results and calculate the true radial distance between each result and the center point (location) to see if it's actually in the radius or not. FIlter out the results that aren't within the radius.
Reference for equation & example code
Return the results (users that are within a certain radius of some location).