Skip to the content.

Proximity search is a type of search that finds items or points that are “near” a given location.

Example:


2️⃣ Why Proximity Search is Useful

  1. Location-based services

    • Food delivery apps, ride-sharing apps, real estate apps
  2. Geospatial analytics

    • Cluster nearby points, heatmaps, traffic analysis
  3. Social networks

    • Find nearby friends or events
  4. Emergency services

    • Find nearest hospitals or fire stations

3️⃣ How Proximity Search Works

Step 1: Represent Locations

Step 2: Measure Distance

Common distance formulas:

  1. Haversine formula (for Earth’s curvature):

[ d = 2 \cdot R \cdot \arcsin\left(\sqrt{\sin^2\left(\frac{\Delta \phi}{2}\right) + \cos \phi_1 \cdot \cos \phi_2 \cdot \sin^2\left(\frac{\Delta \lambda}{2}\right)}\right) ]

  1. Euclidean distance (for small areas, flat approximation):

[ d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2} ]


Naive search → check distance for all points → O(n) → slow for large datasets.

Efficient methods:

  1. Spatial Indexing

    • R-trees: Hierarchical rectangles, fast range queries
    • Quadtrees / K-d trees: Divide space into regions for faster search
  2. Geohash

    • Encode coordinates into strings
    • Nearby locations → share common prefix
    • Quickly filter candidates before calculating exact distance
  3. S2 Geometry / H3

    • Partition Earth into hexagonal cells for scalable proximity queries

4️⃣ Example Workflow (Using Geohash)

  1. Encode all points with Geohash
  2. Query for all points sharing the prefix of target location (covers nearby area)
  3. Filter by exact distance (Haversine)

Example:


5️⃣ Use Cases

Scenario How Proximity Search is Used
Ride-sharing Find nearest drivers to passenger
Food delivery Find restaurants within delivery radius
Social apps Show nearby friends/events
Real estate Show properties near user location
Logistics Find nearest warehouse or hub

6️⃣ Summary