1 | var haversine = (function() {
var toRad = function(num) {
return num * Math.PI / 180
}
return function haversine(start, end, options) {
var miles = 3960
var km = 6371
options = options || {}
var R = options.unit === 'km' ? km : miles
var dLat = toRad(end.latitude - start.latitude)
var dLon = toRad(end.longitude - start.longitude)
var lat1 = toRad(start.latitude)
var lat2 = toRad(end.latitude)
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2)
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a))
if (options.threshold) {
return options.threshold > (R * c)
} else {
return R * c
}
}
})()
| ready |
2 | var haversine = (function() {
var toRad = function(num) {
return num * Math.PI / 180
}
return function haversine(start, end, options) {
var miles = 3960
var km = 6371
options = options || {}
var R = options.unit === 'km' ? km : miles
var dLat = toRad(end.latitude - start.latitude)
var dLon = toRad(end.longitude - start.longitude)
var lat1 = toRad(start.latitude)
var lat2 = toRad(end.latitude)
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2)
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a))
if (options.threshold) {
return options.threshold > (R * c)
} else {
return R * c
}
}
})()
| ready |