Prompt
I need compute near retail stores for local promotions and inventory checks
Latest observation
Oct 26, 2026
OpenAI APIWeb search: off
You can compute “nearby retail stores” by using store locations plus either:
- straight-line distance between coordinates, or
- driving distance/time via a maps/routing API.
Typical approach
1) Store your data
You’ll need a table like:
store_idstore_namelatitudelongitude- maybe
address,city,postal_code
And your target point:
- customer location, promo center, warehouse, or user GPS coordinates
2) Compute proximity
Option A: Fast and simple — Haversine distance
Use this when you just need “stores within X miles/km”.
from math import radians, sin, cos, sqrt, asin
def haversine(lat1, lon1, lat2, lon2):
R = 6371.0 # km
dlat = radians(lat2 - lat1)
dlon = radians(lon2 - lon1)
a = sin(dlat/2)**2 + cos(radians(lat1)) * cos(radians(lat2)) * sin(dlon/2)**2
c = 2 * asin(sqrt(a))
return R * c
Example:
target = (40.7128, -74.0060) # NYC
stores = [
{"name": "Store A", "lat": 40.7306, "lon": -73.9866},
{"name": "Store B", "lat": 40.6500, "lon": -73.9500},
]
nearby = []
for s in stores:
d = haversine(target[0], target[1], s["lat"], s["lon"])
if d <= 10: # within 10 km
nearby.append((s["name"], d))
print(sorted(nearby, key=lambda x: x[1]))
3) For local promotions / inventory checks
Common business logic:
- Find stores within radius
- Rank by distance
- Filter by inventory availability
- Check promo eligibility by region/store cluster
Example logic:
- locate all stores within 5 miles
- only include stores with
inventory_count > 0 - prioritize by nearest distance
4) If you need accurate travel distance
Use:
- Google Maps Distance Matrix API
- Mapbox Directions API
- Here Routing API
This gives:
- travel time
- driving distance
- traffic-aware estimates
5) SQL-based proximity queries
If you use PostgreSQL with PostGIS, you can do this efficiently:
SELECT store_id, store_name
FROM stores
WHERE ST_DWithin(
geography(ST_MakePoint(longitude, latitude)),
geography(ST_MakePoint(:lon, :lat)),
5000
);
5000 = 5000 meters.
Recommended setup for your use case
For promotions and inventory checks, a good pipeline is:
- Geocode store addresses to lat/lon
- Store them in a DB
- Run radius queries for candidate stores
- Join with inventory data
- Trigger promotions for stores that match the location rule
If you want, I can give you:
- a Python script
- a SQL/PostGIS query
- or an API design for computing nearby retail stores automatically.
Brands