Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix haversineFunction

  • Loading branch information...
commit 2608bba2e5fb68fb892ca0226d830dcc86250b68 1 parent fcb2193
Jamison Dance authored
Showing with 5 additions and 15 deletions.
  1. +5 −15 tolmey.js
View
20 tolmey.js
@@ -5,30 +5,20 @@
"use strict";
function Tolmey() {
- this.RADIUS_OF_EARTH_IN_METERS = 6367560;
+ this.RADIUS_OF_EARTH_IN_METERS = 6378100;
this.TILESIZE = 256;
}
//Returns the central angle between two points in latiude and longitude
Tolmey.prototype.haversineFunction = function (lat_start, long_start, lat_end, long_end) {
- var dLat = (lat_end - lat_start),
- dLon = (long_end - long_start),
+ var dLat = this.degreesToRadians(lat_end - lat_start),
+ dLon = this.degreesToRadians(long_end - long_start),
lat1 = this.degreesToRadians(lat_start),
- lat2 = this.degreesToRadians(lat_end),
- dLatRadians = this.radiansToDegrees(dLat),
- dLonRadians = this.radiansToDegrees(dLon);
+ lat2 = this.degreesToRadians(lat_end);
- var a = Math.pow(Math.sin(dLatRadians / 2), 2) +
- Math.pow(Math.sin(dLonRadians / 2), 2) *
- Math.cos(lat1) * Math.cos(lat2);
+ var a = Math.pow(Math.sin(dLat/2), 2) + Math.cos(lat1)*Math.cos(lat2)*Math.pow(Math.sin(dLon/2),2);
var centralAngle = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
return centralAngle;
- // return 2 * Math.asine( Math.sqrt(Math.pow(Math.sin((lat_end - lat_start) / 2), 2) +
- // Math.cos(lat_start) *
- // Math.cos(lat_end) *
- // Math.pow(Math.sin((long_end - long_start) / 2), 2)
- // )
- // );
};
Please sign in to comment.
Something went wrong with that request. Please try again.