JavaScript calculates the distance of two GPS coordinates __java

Source: Internet
Author: User
Tags asin cos pow sin
here is a function of JS to compute the distance of two GPS points:

PHP calculates the distance between two GPS points
MySQL calculates the distance between two GPS coordinates
JavaScript calculates the distance function between two GPS points Torad (d) {return d * math.pi/180;} function Getdisance (LAT1, Lng1, LAT2, lng2) {#lat For latitude, LNG is longitude, must not be mistaken var dis = 0; var radLat1 = Torad (LAT1); var radLat2 = Torad (LAT2); var deltalat = Radlat1-radlat2; var deltalng = Torad (lng1)-Torad (LNG2); var dis = 2 * math.asin (MATH.SQRT (Math.pow (Math.sin (DELTALAT/2), 2) + Math.Cos (RADLAT1) * MATH.COS (RADLAT2) * MATH.POW (M Ath.sin (DELTALNG/2), 2)); return dis * 6378137; Alert (Getdisance (39.91917,116.3896,39.91726,116.3940));

1 2 3 4 5 6 7 8 9 Ten function Torad (d) {   return d * Ma Th. pi/180; function Getdisance (LAT1, Lng1, LAT2, lng2) {#lat为纬度, LNG is longitude, must not be mistaken      var dis = 0;   ;    var radLat1 = Torad (LAT1);      var radLat2 = Torad (LAT2);      var deltalat = radlat1-radlat2;      var deltalng = Torad (lng1)-Torad (LNG2);      var dis = 2 * Math. ASIN (Math. sqrt (Math. Pow (DELTALAT/2), 2) + math. cos (RADLAT1) * math. cos (RADLAT2) * Ma Th. Pow (Math. Sin (DELTALNG/2), 2));      return dis * 6378137; Alert (   getdisance (39.91917, 116.3896, 39.91726, 116.3940));
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.