Menu

How We Built "Donations Near Me" with MongoDB and Leaflet.
📰

How We Built "Donations Near Me" with MongoDB and Leaflet.

DEV Community: mongodb·Devisetty Charmi·15 days ago
#i9SfQf4z
#devtomongodb#devto#dev#coordinates#index
Long article (632 words) — no AI summary yet.
Reading 0:00
15s threshold

By Devisetty Charmi, Katta Lasya, Veeramaneni Sruthi, Yasa Sowmya

During the creation of GiveBridge, a platform for local donations whereby donors list particular items for receivers to get, we ran into a fundamental question: how can a receiver find donations nearby?

City name search is effective but not enough. Someone in a big city can see an item listed in his “city” which is located 30 km from him. Therefore, we positioned ourselves to create a location-based search functionality. The following is our approach to create it using MERN stack.

Step 1: Storing the geographical position in the GeoJSON format.

In this case, we've created a property in the Mongoose schema that represents the geographical position of the donation. However, the usual blunder here is mixing up the order of coordinates; in GeoJSON, the latitude must be indicated after the longitude.

Step 2: Create a 2d sphere index

Simply storing coordinates is insufficient.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.