Prompt
compute near users API
Latest observation
Oct 26, 2026
OpenAI APIWeb search: off
If you mean “compute nearby users” for an API, the usual approach is:
- Get the current user’s latitude/longitude
- Store other users’ latitude/longitude
- Query users within a radius using a distance formula or geospatial index
Common API pattern
Request
GET /users/nearby?lat=37.7749&lng=-122.4194&radius=5000
lat,lng: current locationradius: search radius in meters or miles
Example response
{
"users": [
{
"id": 1,
"name": "Alice",
"distance_m": 320
},
{
"id": 2,
"name": "Bob",
"distance_m": 1240
}
]
}
If you’re implementing it
You can compute distance using the Haversine formula:
function haversine(lat1, lon1, lat2, lon2) {
const R = 6371000; // meters
const toRad = d => d * Math.PI / 180;
const dLat = toRad(lat2 - lat1);
const dLon = toRad(lon2 - lon1);
const a =
Math.sin(dLat / 2) ** 2 +
Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) *
Math.sin(dLon / 2) ** 2;
return 2 * R * Math.asin(Math.sqrt(a));
}
Best practice
- For small datasets: compute in code
- For production-scale apps: use PostGIS, MongoDB geospatial queries, or Redis GEO
If you want, I can help you build the full “near users” API in Node.js, Python, Laravel, or SQL.