Skip to content

Instantly share code, notes, and snippets.

@jayhutfles
Last active August 29, 2015 14:08
Show Gist options
  • Save jayhutfles/b2583e0af3343e7da3bc to your computer and use it in GitHub Desktop.
Save jayhutfles/b2583e0af3343e7da3bc to your computer and use it in GitHub Desktop.
Air distance function in Scala
import math._
def airDistance(lat1: Double, lon1: Double, lat2: Double, lon2: Double) = {
val R = 3958.75
val dLat = (lat2 - lat1).toRadians
val dLon = (lon2 - lon1).toRadians
val a = pow(sin(dLat/2),2) + pow(sin(dLon/2),2) * cos(lat1.toRadians) * cos(lat2.toRadians)
R * 2 * asin(sqrt(a))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment