Now the application of geo-information is very hot, whether it is from the location of Google map information, or through the iphone or Android, such as mobile terminals with GPS modules to obtain geographical information, are decimal latitude and longitude information. We may need to compute the distance between two points on the Earth's surface when we do the actual application, and here is the example language of JavaScript, which provides a computational method, which is also the method used by Google map.
1. Decimal latitude and longitude degrees, minutes, seconds view plain copy to clipboard print? function Dec2deg (dec) {var dec = math.abs (dec) + ""; Dec = Dec.split ("."); var deg = dec[0]; DEC[1] = "0." + dec[1]; var min_sec = dec[1] * 3600; var min = Math.floor (MIN_SEC/60); var sec = (Min_sec-(min * 60)); return [deg, Min, sec]; }
function Dec2deg (dec) {
var dec = math.abs (dec) + "";
Dec = Dec.split (".");
var deg = dec[0];
DEC[1] = "0." + dec[1];
var min_sec = dec[1] * 3600;
var min = Math.floor (MIN_SEC/60);
var sec = (min_sec-(min *));
return [deg, Min, sec];
}
2. Degrees, minutes, seconds to decimal latitude and Longitude view plain copy to clipboard print? function Deg2dec (deg, Min, sec) {var deg = Math.Abs (deg); var min = math.abs (min); var sec = Math.Abs (sec); return deg * 1 + (sec * 1 + min * 60)/3600; }
function Deg2dec (deg, Min, sec) {var deg = Math.Abs (deg);
var min = math.abs (min);
var sec = Math.Abs (sec);
return deg * 1 + (sec * 1 + min * 60)/3600; }
3. Calculate the distance between two points view plain copy to clipboard print? Radians conversion Function rad (d) { return d * math.pi / 180.0; } // calculates the distance, resulting in the unit km (km) function caldistance (LAT1,  LNG1, LAT2, LNG2) { if ( math.abs ( lat1 ) > 90 ) | | ( math.abs ( lat2 ) > 90 ) ) return false; if ( math.abs ( lng1 ) > 180 ) | | ( math.abs ( lng2 ) > 180 ) ) return false; var radlat1 = rad (LAT1); var radlat2 = rad (LAT2); var a = radlat1 - radlat2; var b = rad (lng1) - rad (lng2); var s = 2 * math.asin ( math.sqrt ( math.pow ( Math.sin) ( a/2 ), 2 ) + math.cos ( radLat1 ) * math.cos ( radlat2 ) * math.pow ( math.sin b/2 ) (, 2 ) ) ); s = s * 6378.137 ; // Earth radius 6378.137 s = math.round (s * 10000) / 10000; return s; }