I have a Model
called Place
having a simple structure:
| id | name | lat | lon |
|----|-------|-----------|-------------|
| 1 | hotel | 33.755787 | -116.359998 |
| 2 | shop | 44.968046 | -94.420307 |
| 3 | park | 44.333304 | -91.493768 |
What I need is something like Place::whereRadius(100)->get()
or some accurate latitude/longitude so that I can build a query like this:
Place::whereBetween('lat',latitudes)->whereBetween('lon',longitude)->get();
Currently my approach is to get lat/lon points of a circle of radius
apart from my desired lat/lon point which I did via turf.js
on frontend and got an array of lat/lon coordinates like this:
//example not real calculation
[
[33.755787, -116.359998],
[44.968046, -94.420307],
[44.333304, -91.493768]
]
My next step was to calculate possible max and min points within the area of the above received circle but it's not promising accurate results with larger datasets or larger circles even in small datasets.
Is there an efficient way to query lat/lon based on radius & with some Eloquence if possible?
Edit I am looking for Laravel/Eloquent way of doing it. Raw MySQL based radius as suggested can technically work but isn't exactly what I asked for in the question