Google Maps calculates the two-point distance function based on the longitude and latitude.

Source: Internet
Author: User

Latitude

Longpolling longitude

Calculate the two-point distance function based on the longitude and latitude in the Google Maps script.

Private const double earth_radius = 6378.137;
Private Static double rad (double D)
{
Return D * Math. PI/180.0;
}

Public static double getdistance (double LAT1, double lng1, double LAT2, double lng2)
{
Double radlat1 = rad (LAT1 );
Double radlat2 = rad (LAT2 );
Double A = radlat1-radlat2;
Double B = rad (lng1)-rad (lng2 );
Double 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 * 10000)/10000;
Return S;
}

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.