How can I get all the points within a given range depending on its latitude and longitude?

: I have a db with three tables, users, locations, stocks;

users: id, name, email

in places where I have: id, place, lati, logi

In stock I have: id, user_id, product, total_count, location_id

I am pretty new and I managed to join all the tables:

$qry = "
SELECT COUNT(id)
  FROM stock
  LEFT
  JOIN users 
   ON stock.user_id= users.id
  LEFT
  JOIN locations
   ON stock.location_id= locations.id ";

But what I hope to do is sort by distance using lati and logi. So, for example, I want everything to be within 25 miles, sorted closest to the farthest.

How can I remove this from the script?

I did some search queries, but all I found is showing me how I can get the distance between two points, but what do I want to be able to use one set of points and get everything within X miles of it?

Not sure if all this makes sense?

+4
1

:

pow(CentralLati - LatitudeofCircle, 2) + pow(CentralLongi - LongitudeofCircle, 2) <= 4

CentralLati, CentralLongi = > A

LatitudeofCircle, LongitudeofCircle = > 25kms A.

.

, .

+1

Source: https://habr.com/ru/post/1623026/


All Articles