Calculate distance based on two-point latitude and longitude

Source: Internet
Author: User
Tags cos

function Getgreatcircledistance (lat1,lng1,lat2,lng2) {if (!LAT1 | |!lng1 | |!lat2 | |!lng2) {return-1;}    var v = 0;    var radLat1 = Getrad (LAT1);    var radLat2 = Getrad (LAT2);    var a = RADLAT1-RADLAT2;    var B = Getrad (lng1)-Getrad (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*earth_radius;    s = Math.Round (s); if (s<1000) {v = s.tofixed (0) + ' m '; } else{s = s/1000;v = s.tofixed (1) + ' km '; } return v;} var lat1 =//Current latitude var lng1 =//Current longitude var lat2 =//target latitude var lng2 =//target Longitude v = getgreatcircledistance (lat1,lng1,lat2,lng2)

More detailed URL: http://www.360doc.com/content/10/1228/10/284485_81937345.shtml

Calculate distance based on two-point latitude and longitude

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.