Get closest cities of selected location.
« on: July 14, 2024, 06:10:10 PM »
How to get closest cities list of selected location. Example if we have an city id or slug then we want to closest cities names using longitude and langtitude.

Suggest query for it

*

MB Themes

Re: Get closest cities of selected location.
« Reply #1 on: July 16, 2024, 09:32:29 AM »
There exists various variants on this.
One of them could be:
Code: [Select]
SELECT
id,
(
   3959 *
   acos(cos(radians(37)) *
   cos(radians(lat)) *
   cos(radians(lng) -
   radians(-122)) +
   sin(radians(37)) *
   sin(radians(lat )))
) AS distance
FROM markers
HAVING distance < 28
ORDER BY distance LIMIT 0, 20;
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots