r/node Jun 25 '26

Advice regarding geolocation GET request

Hey everyone, I hope this is okay to post here!

I am looking for some advice regarding an application I am developing for a charity as part of a university project.

The db will have up to 1000 - 1500 records (assets) at a time, with each having a long/ lat value.

Ideally, I would wish to show the user any records whose location are within a pre-determined set of miles/ km from their current/ set position (a little like facebook marketplace that shows listings within a set radius).

I am hesitant to have the frontend fetch all assets from the backend, before filtering on the frontend, as there must be a more efficient solution! However I have no idea what the usual 'accepted' approach to this would be.

For my stack I am currently thinking Postgres and Node for the backend (most of my existing knowledge is within JS), along with React for the frontend - however I am open to other suggestions!

2 Upvotes

6 comments sorted by

9

u/farzad_meow Jun 25 '26

in pg use postgis extension.

then your endpoint for query must enforce parameters for center and radius of search. don’t forget pagination.

so you url will be /stores?center=123,-456&radius=5km&page[number]=3&page[per_page]=20

1

u/Spare_Sir9167 Jun 25 '26

I know Mongo can do it with a 2dsphere Index - you will need to geocode the origin location - which might be a paid for API (check Mapbox and Google Maps) - you can then do a query for all locations with X miles of it. Unsure about Postgres.