# DistanceBetweenPoints ( Lat1 ; Lon1 ; Lat2 ; Lon2 ; Units )

Calculates the distance between any two points on Earth.

Sample input:
DistanceBetweenPoints ( 0.592539; 2.066470; 0.709186; 1.287762; "nm" )
Sample output:
2144

Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

Based on "Aviation Formulary v1.42" by Ed Williams <http://williams.best.vwh.net/avform.htm>.

Calculates the distance between two points on Earth (assuming earth's radius is 6366.71 km) based on the second "Great Circle Distance Between Points" formula that proports to give less rounding error for short distances.

Since FMP's formula dictionary does not contain asin, the distance formula is modified to use atan as described in the "Implementation Notes". The format of the custom function below attempts to make these original formulae explicit.

Latitude and Longitude are entered in decimal degrees.

The Units variable accepts "radians", "nm", "km" and "miles". Empty latitude, longitude variables, or unrecognised units entries cause the function to return "?".

 NA, OzMar 22, 2009 How do I use this correctly? I have copied into Custom Functions but get an error "The specified parameter cannot be found" Lat1 is highlighted. Any ideas?
 Vaughan BromfieldJun 3, 2009 It works for me... All I can suggest is that you make sure you add "Lat1" and the other parameters to the second panel in the custom function dialog.
 Eric, SJSUJun 9, 2009 I can't get the sample input to give me the sample output. What is the order of the parameters in the function definition?
 Vaughan BromfieldJun 21, 2009 The sample input should be: DistanceBetweenPoints ( 0.592539; 2.066470; 0.709186; 1.287762; "nm" )
 Vaughan BromfieldJun 21, 2009 My bad, the data in the sample is incorrect. I have quoted lats and lons in radians and it should be in decimal degrees. Enter this data into the CF: Lat1 = 33 + (57/60) ; Lon1 = 118 + (24/60) ; Lat2 = 40 + (38/60) ; Lon2 = 73 + (47/60) ; ... and the result is 2143.7261012545210023.

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

### Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: