Python calculates distance samples based on latitude and longitude _python

Source: Internet
Author: User
Tags cos sin

Copy Code code as follows:

/**
 * calculates the distance between two points
 * @param _lat1-start latitude
 * @par Am _lon1-start Longitude
 * @param _lat2-end latitude
 * @param _lon2-end longitude
 * @return km (rounded)
 */
public static double getdistance (double _lat1,double _lon1, double _lat2,double _lon2) {
 double LA T1 = (math.pi/180) *_lat1;
 double lat2 = (math.pi/180) *_lat2;

 double lon1 = (math.pi/180) *_lon1;
 double lon2 = (math.pi/180) *_lon2;

 //The earth radius
 double R = 6378.1;

 double D =  Math.acos (Math.sin (LAT1) *math.sin (LAT2) +math.cos (LAT1) *math.cos (LAT2) *math.cos ( Lon2-lon1)) *r;

 return New BigDecimal (d). Setscale (4,BIGDECIMAL.ROUND_HALF_UP). Doublevalue ();
}

public static void Main (string[] args) {
 system.out.println getdistance (45.73990, 126.55893, 45.73876, 126.55037));
}

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.