3 people like it.

Calculate distance between two GPS latitude-longitude points.

Calculate distance between two GPS latitude-longitude points.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
open System

let ``calculate distance`` (p1Latitude,p1Longitude) (p2Latitude,p2Longitude) =
    let r = 6371.0; // km
    let dLat = (p2Latitude - p1Latitude) * Math.PI / 180.0
    let dLon = (p2Longitude - p1Longitude) * Math.PI / 180.0
    let lat1 = p1Latitude * Math.PI / 180.0
    let lat2 = p2Latitude * Math.PI / 180.0

    let a = Math.Sin(dLat/2.0) * Math.Sin(dLat/2.0) +
            Math.Sin(dLon/2.0) * Math.Sin(dLon/2.0) * Math.Cos(lat1) * Math.Cos(lat2)
    let c = 2.0 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1.0-a))
    r * c
namespace System
val ( calculate distance ) : p1Latitude:float * p1Longitude:float -> p2Latitude:float * p2Longitude:float -> float

Full name: Script.( calculate distance )
val p1Latitude : float
val p1Longitude : float
val p2Latitude : float
val p2Longitude : float
val r : float
val dLat : float
type Math =
  static val PI : float
  static val E : float
  static member Abs : value:sbyte -> sbyte + 6 overloads
  static member Acos : d:float -> float
  static member Asin : d:float -> float
  static member Atan : d:float -> float
  static member Atan2 : y:float * x:float -> float
  static member BigMul : a:int * b:int -> int64
  static member Ceiling : d:decimal -> decimal + 1 overload
  static member Cos : d:float -> float
  ...

Full name: System.Math
field Math.PI = 3.14159265359
val dLon : float
val lat1 : float
val lat2 : float
val a : float
Math.Sin(a: float) : float
Math.Cos(d: float) : float
val c : float
Math.Atan2(y: float, x: float) : float
Math.Sqrt(d: float) : float
Raw view Test code New version

More information

Link:http://fssnip.net/7P8
Posted:8 years ago
Author:Tuomas Hietanen
Tags: latitude-longitude , gps , distance