Monday, January 21, 2008

Need JavaScript to convert decimal degrees to miles

//Note this is an estimate based on a simple spheroid
function distanceConverter(x1,y1,x2,y2) {
  // distance between 2 points from decimal degrees to miles
  // where x values represent longitude
  // where y values represent latitiude
  dx = 69.172 * (x2 - x1) * Math.cos( y1 / 57.3);
  dy = 69.172 * (y2 - y1);
  var dist = Math.sqrt(dx * dx + dy * dy);
  return dist;
}

No comments: