<! DOCTYPE HTML Public"-//W3C//DTD XHTML 1.0 transitional//en" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD">"http://www.w3.org/1999/xhtml">"Text/javascript"Src="Http://apps.bdimg.com/libs/jquery/1.6.4/jquery.js"></script> <script type="Text/javascript">varEarth_radius =6378137.0;//Unit M varPI =Math.PI; function Getrad (d) {returnD * PI/180.0; } /** * Caculate the Great circle distance * @param {object} lat1 (Latitude 1) * @param {object} lng1 (longitude 1) * @param {object} lat2 (Latitude 2) * @param {object} lng2 (longitude 2)*/ //The first method: This algorithm is the earth as a rule of the sphere to calculate, this method is not very accurate, it depends on the accuracy of your positioningfunction Getgreatcircledistance (LAT1, Lng1, LAT2, lng2) {varRADLAT1 =Getrad (LAT1); varRADLAT2 =Getrad (LAT2); varA = RADLAT1-RadLat2; varb = Getrad (lng1)-Getrad (LNG2); vars =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 *Earth_radius; S= Math.Round (S *10000) /10000.0; alert (s); } //The first method: The earth is elliptical, so there will be this algorithmfunction Getflatterndistance (LAT1, Lng1, LAT2, lng2) {varf = Getrad ((lat1 + lat2)/2); varg = Getrad ((LAT1-LAT2)/2); varL = Getrad ((lng1-lng2)/2); varSG =Math.sin (g); varSL =Math.sin (L); varSF =Math.sin (f); vars, c, W, R, D, H1, H2; varA =Earth_radius; varFL =1/298.257; SG= SG *SG; SL= SL *SL; SF= SF *SF; S= SG * (1-SL) + (1-SF) *SL; C= (1-SG) * (1-SL) + SF *SL; W= Math.atan (Math.sqrt (S/c)); R= MATH.SQRT (S * c)/W; D=2* W *A; H1= (3* R-1) /2/C; H2= (3* R +1) /2/s; Alert (d* (1+ FL * (H1 * SF * (1-SG)-H2 * (1-SF) *sg)); } $ (function () {getflatterndistance (28.89596,105.443985,28.896462,105.444291); }); </script>63.3422</body>JS calculates the distance between the Earth's two latitude and longitude