5

I'm guessing that the units it uses is meters (m), but it doesn't seem clear from the documentation I've found. Is this correct?

If so, just to verify, in order to convert between miles/meters, I presume these functions should do the trick:

public static function mi2m($mi) {  // miles to meters
    return $mi * 1609.344;
}
public static function m2mi($m) {  // meters to miles
    return $m * 0.000621371192;
}
Charles
  • 50,943
  • 13
  • 104
  • 142
Matt Huggins
  • 81,398
  • 36
  • 149
  • 218

4 Answers4

7

The documentation seems unambiguous. Most of the module uses metres by default. But you can change that to any units you like by modifying a single function, earth. Presumably all the other functions use this function so your units are able to be arbitrary if this is overriden.

Note though that the point <@> point operator always works in miles, and this can't be adjusted.

Your conversion functions are correct, but that's easy to check as well:

ire_and_curses
  • 68,372
  • 23
  • 116
  • 141
1

The radius of the Earth is obtained from the earth() function. It is given in meters

If the radius of the Earth is in meters, I'm gonna guess that your math is going to be wrong unless you also use meters.

Ana Betts
  • 73,868
  • 16
  • 141
  • 209
1

The documentation is clear: paragraph 2 of section F.8.1 says: “The radius of the Earth is obtained from the earth() function. It is given in meters.”

Arthur Reutenauer
  • 2,622
  • 1
  • 17
  • 15
  • 1
    Yeah, but that's talking about the earth() function, it doesn't mention what units the other functions. I deduced they all use meters from this line, but it is definitely *not* clear. – Matt Huggins Oct 23 '09 at 21:36
  • 1
    It's apparently expressed in terms of what earth() returns (that's how I understand the comment saying that can modify earth() to your needs). You're on a sphere (that's an approximation but the manual mentions it), the only distance that's relevant is the radius. All the other values are either angles, or distances where the radius is a factor (i.e., if the radius would be multiplied by 2, all the distances that you compute would also be). – Arthur Reutenauer Oct 23 '09 at 21:51
-1

If you have input in metres, then use it like this:

radius_in_metres/1.609
Simmi Badhan
  • 493
  • 1
  • 5
  • 16
  • 1
    that's what Matt Huggins said, except he's not wrong by a factor of approximately 1000 – Jasen Feb 14 '18 at 00:28