-1

I have the following query, that selects places withing given radius:

SELECT *
FROM (
  SELECT 
    group, 
    name,  
    111.1111 *
    DEGREES(ACOS(LEAST(1.0, COS(RADIANS(".$lat."))
       * COS(RADIANS(t1.lat))
       * COS(RADIANS(".$lon.") - RADIANS(t1.lon))
       + SIN(RADIANS(".$lat."))
       * SIN(RADIANS(t1.lat))))) AS distance
  FROM t1
) AS grp
WHERE distance < 10

It works well, but I'm not sure if returned results are in miles or kilometers. I suspect KM and if that's the case, how do I convert it to miles?

santa
  • 12,234
  • 49
  • 155
  • 255
  • Where did you get the formula from? Did the author not give you the units? – Asteroids With Wings Jan 21 '21 at 20:51
  • One question per question please – Asteroids With Wings Jan 21 '21 at 20:54
  • Is this really a question for Stack Overflow? Finding out if it's miles or kilometers is as simple as running a query for a pair of coordinates and comparing it with the answer you get for those coordinates off Google. If it is indeed in km, converting to miles is also a simple multiplication by a constant. [How much research effort is expected of Stack Overflow users?](//meta.stackoverflow.com/a/261593/843953) – Pranav Hosangadi Jan 22 '21 at 16:07

1 Answers1

0

Your code appears to originate in this Stack Overflow answer by O. Jones, which also states:

The constant 111.1111 is the number of kilometres per degree of latitude, based on the old Napoleonic definition of the metre as one ten-thousandth of the distance from the equator to the pole.

Accordingly, the original query uses the name distance_in_km for the result.

Jones goes on to say:

If you want statute miles instead of kilometres, use 69.0 instead.

Asteroids With Wings
  • 17,071
  • 2
  • 21
  • 35
  • Oh, cool. It appears I found the query that was borrowed from the OP you mentioned. Thanks. – santa Jan 21 '21 at 21:25
  • @Asteroids presumably because all you do in this answer is quote and link another answer. This could have been a comment instead of an answer – Pranav Hosangadi Jan 24 '21 at 00:48
  • @PranavHosangadi No, comments are not for answering questions, ever. This answer answers the question, with the facts inline _and_ references to the source of the information. What more do you want!? – Asteroids With Wings Jan 24 '21 at 15:08