Calculate the Distance Based on the longitude and latitude of two points

Source: Internet
Author: User
Tags acos
How are the longitude and latitude dimensions determined? The earth is constantly rotating around the Earth's axis (the Earth's axis is a hypothetical line through the earth's north and south poles and the Earth's Center), draw a large circle perpendicular to the Earth's axis in the waist, so that every point in the circle is equal to the distance between the north and south poles. This circle is called the "Equator ". On the north and south sides of the Equator, draw many circles parallel to the equator, which are "latitude circles". The line segments that constitute these circles are called weft wires. We set the equator to zero latitude, 90 degrees to the north to the south, and north to the south of the equator. The North Pole is 90 degrees north latitude, and the South Pole is 90 degrees south latitude. The latitude and height also indicate the hot and cold weather of the climate, for example, there is no winter in the Equator and low latitude regions, there is no summer in the polar and high latitude regions, and the middle latitude regions have distinct seasons. Second, from the Arctic point to the South Pole, we can draw many large circles perpendicular to the earth's equator in the North-South direction, which is called the "Meridian Circle". The line segments that constitute these circles are called the meridian lines. In the year 1884, the international regulation adopted the longitude line of the Greenwich Observatory in the suburbs of London as the starting point for calculating the longitude, that is, 0 minutes 0 seconds, longitude, also known as the "primary meridian ". In the east of it is the east longitude, a total of 180 degrees; In its West is the west longitude, a total of 180 degrees. Because the earth is circular, the longitude of the east longitude is 180 degrees and the longitude line of the west longitude is the same. Each country defines the 180-degree longitude line as the "International Date change line ". In order to avoid using two different dates in the same region, the international date variation slightly deviated in case of land. Each longitude and latitude can be subdivided into 60 minutes, and each minute is divided into 60 seconds and decimal places in seconds. With the geographic line, we can determine the specific location of every place on the earth and express it on a map or globe. For example, what is the longitude and latitude of Beijing? We can easily find out from the map that the longitude is 116 degrees 24 minutes, And the latitude is 39 degrees 54 minutes. If the longitude of a ship sailing in the sea is measured, the position and Forward Direction of the ship in the ocean can be determined. The latitude is 90 degrees. The equator is 0 degrees, arranged to two poles. The smaller the circle, the larger the degree. The horizontal line is the latitude, and the vertical line is the longitude. Of course, it can be computed by quadratic equation of four elements. Longitude and latitude are both an angle. Longitude is the angle between two sides and the plane of the longitude line. Since all the meridian lines are of the same length, in order to determine a starting point for the longitude, after consultation at the 1884 International Conference, it was decided to go through the Greenwich Mean Royal Observatory (old site) on the outskirts of London and the south bank of the River Bank of England) the meridian line of a Main Meridian Cross is the starting meridian line, called the primary Meridian. The primary meridian plane is the start plane and the end plane is the local meridian plane. The longitude of a point is the angle between the longitude plane of the point and the primary meridian plane. On the equator, the self-Primary meridian plane is used as the starting point and measured to the east and west respectively. The value to the east is called the east longitude, and the value to the west is called the west longitude. It can be seen that the longitude of a region is the direction and angular distance of the region to the primary Meridian. The prime meridian is 0 ° longitude, the maximum value of east longitude is 180 °, the maximum value of west longitude is 180 °, and the longitude line of east longitude and west longitude is the same meridian, and collectively referred to as 180 ° longitude line. Latitude is a line angle. The START plane is the equator plane, and the line is the local ground normal. The so-called normal, that is, the line perpendicular to the reference flat surface. The latitude of a place is the angle between the normal of the place and the Equator plane. Latitude is measured on the local longitude line. It is measured from the equator to the South and the North. The North is called the north latitude, and the south is called the south latitude. It can be seen that the latitude of a region is the direction and angular distance of the region to the equator. The equator is a 0 ° weft, and the maximum value of the north latitude is 90 °, that is, the northern point; the maximum value of the south latitude is 90 °, that is, the southern pole. Latitude and longitude interchange degree converted into degree minute second degree (DDD): E 108.90593 degrees N 34.21630 degrees how to convert degree (DDD): 108.90593 degrees converted into degree minute second (DMS) east longitude E 108 degrees 54 minutes 22.2 seconds? The conversion method is to change the 108.90593 integer to 108 degrees, and use 0.90593*60 = 54.3558 to retrieve the entire digit 54 (points ), 0.3558*60 = 21.348 and then the integer is 21 (seconds), so it is converted to 108 degrees 54 minutes 21 seconds. similarly, the method for converting degrees into seconds (DMS): Dong Jing e 108 degrees 54 minutes 22.2 seconds to degrees (DDD) is as follows: 108 degrees 54 minutes 22.2 seconds = 108 + (54/60) + (22.2/3600) = 108.90616 degrees because the decimal point is retained During computation, there is a certain error in the positive and negative computation, but the error is not significantly affected. The error of one second is a few meters. GPS drivers can use the above method to convert the Unit coordinates they need.

Decimal representation of longitude and latitude
For two vertices, when the latitude is equal:
Longitude is at intervals of 0.00001 degrees, with a Distance Difference of about 1 meter. at intervals of 0.0001 degrees, the distance is about 10 meters. at intervals of 0.001 degrees, the distance is about 100 meters. at intervals of 0.01 degrees, the distance is about 1000 meters, and the distance is about 0.1 meters at intervals of 10000 degrees.

For two vertices, when the longitude is equal:
Latitude at every 0.00001 degrees, Distance Difference about 1.1 meters; every 0.0001 degrees, Distance Difference about 11 meters; every 0.001 degrees, Distance Difference about 111 meters; every 0.01 degrees, the distance is about 1113 meters, and the distance is about 0.1 meters at intervals of 11132 degrees.
 



Calculate the distance between two points based on the longitude and latitude of any two points on the ball
Method 1: because the earth is an elliptical body, this is too difficult to calculate. If the earth is a sphere, you can use the following formula: Set the longitude of a point on the earth to a and latitude to B, then, the spatial coordinates of this point are x = cos (B) * Cos (a) y = cos (B) * sin (a) z = sin (B) set the spatial coordinates of the two points on the earth to (x1, Y1, Z1), (X2, Y2, Z2) then their angle is c = ACOs (x1 * X2 + Y1 * y2 + z1 * Z2). If C is the angle, the distance between the two places is C/180 * pI * r, r indicates the mean radius of the earth. The error 6371 does not exceed 1%.
The earth is a quasi-Standard Elliptical body. Its equator radius is 6378.140 km, the polar radius is 6356.755 km, and the average radius is 6371.004 km. If we assume that the Earth is a perfect sphere, its radius is the mean radius of the Earth, which is recorded as R. If the zero-degree longitude line is used as the basis, the distance between the two points can be calculated based on the latitude and longitude of any two points on the Earth's surface. (here, the error caused by the calculation of the earth's surface topography is ignored, only theoretical estimates ). Set the longitude and latitude of the first Vertex a to (Lona, Lata), and the longitude and latitude of the second vertex B to (lonb, latb) based on the zero-degree longitude line, the longitude is a positive value (longpolling), the longitude is a negative value (-longpolling), and the latitude is 90-latitude ), when the latitude value is 90 + (90 + latitude), the two points after processing are counted as (mlona, mlata) and (mlonb, mlatb ). According to the triangle derivation, the following formula is obtained for calculating the distance between two points: c = sin (mlata) * sin (mlatb) * Cos (mlona-mlonb) + cos (mlata) * Cos (mlatb) distance = r * arccos (c) * PI/180
Here, the units of R and distance are the same. If 6371.004 km is used as the radius, distance is the unit of kilometer. If other units such as mile are used, unit conversion is also required, 1Km = 0.621371192mile if only positive and negative processing is performed on the longitude, And the latitude is not 90-latitude (assuming that they are all in the northern hemisphere, and the southern hemisphere is only available in Australia), the formula will be: C = sin (lata) * sin (latb) + cos (lata) * Cos (latb) * Cos (mlona-mlonb) distance = r * arccos (c) * PI/180 or above can be introduced through simple triangle transformation. If the input and output values of trigonometric functions use radians, the formula can also be written as follows:
C = sin (Lata * PI/180) * sin (latb * PI/180) + cos (Lata * PI/180) * Cos (latb * PI/180) * Cos (mlona-mlonb) * PI/180) distance = r * arccos (c) * PI/180 that is: c = sin (Lata/57.2958) * sin (latb/57.2958) + cos (Lata/57.2958) * Cos (latb/57.2958) * Cos (mlona-mlonb)/57.2958) distance = r * arccos (c) = 6371.004 * arccos (c) kilometer = 0.621371192*6371.004 * arccos (c) mile = 3958.758349716768 * arccos (c) mile [Java]View plaincopy
  1. <Span style = "font-size: 14px; font-weight: normal;"> Private Static final double earth_radius = 6378137; // equator radius (unit: m)
  2. /**
  3. * Convert to a radian (RAD)
  4. **/
  5. Private Static double rad (double D)
  6. {
  7. Return D * Math. PI/180.0;
  8. }
  9. /**
  10. * Calculate the distance between two longitude and latitude Based on cosine theorem
  11. * @ Param lon1 precision of the first point
  12. * @ Param LAT1 latitude of the first point
  13. * @ Param lon2 second point Precision
  14. * @ Param lat3 latitude of the second Vertex
  15. * @ Return distance, in km
  16. **/
  17. Public static double lantitudelongitudedist (double lon1, double LAT1, double lon2, double LAT2 ){
  18. Double radlat1 = rad (LAT1 );
  19. Double radlat2 = rad (LAT2 );
  20. Double radlon1 = rad (lon1 );
  21. Double radlon2 = rad (lon2 );
  22. If (radlat1 <0)
  23. Radlat1 = math. PI/2 + math. Abs (radlat1); // south
  24. If (radlat1> 0)
  25. Radlat1 = math. PI/2-math. Abs (radlat1); // north
  26. If (radlon1 <0)
  27. Radlon1 = math. Pi * 2-math. Abs (radlon1); // West
  28. If (radlat2 <0)
  29. Radlat2 = math. PI/2 + math. Abs (radlat2); // south
  30. If (radlat2> 0)
  31. Radlat2 = math. PI/2-math. Abs (radlat2); // north
  32. If (radlon2 <0)
  33. Radlon2 = math. Pi * 2-math. Abs (radlon2); // West
  34. Double X1 = earth_radius * Math. Cos (radlon1) * Math. Sin (radlat1 );
  35. Double Y1 = earth_radius * Math. Sin (radlon1) * Math. Sin (radlat1 );
  36. Double z1 = earth_radius * Math. Cos (radlat1 );
  37. Double X2 = earth_radius * Math. Cos (radlon2) * Math. Sin (radlat2 );
  38. Double y2 = earth_radius * Math. Sin (radlon2) * Math. Sin (radlat2 );
  39. Double Z2 = earth_radius * Math. Cos (radlat2 );
  40. Double D = math. SQRT (x1-X2) * (x1-X2) + (Y1-Y2) * (Y1-Y2) + (Z1-Z2) * (Z1-Z2 ));
  41. // Cosine theorem for Angle Calculation
  42. Double Theta = math. ACOs (earth_radius * earth_radius + earth_radius * earth_radius-D * D)/(2 * earth_radius ));
  43. Double Dist = Theta * earth_radius;
  44. Return Dist;
  45. } </Span>

Calculate the Distance Based on the longitude and latitude of two points

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.