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

Source: Internet
Author: User
`How are these cable cables determined? The earth is constantly rotating around the Earth's axis (the Earth's axis is a path through the north and south poles of the Earth and the Center of the EarthImaginary line), draw a large circle perpendicular to the ground axis in the waist of the earth, so that every point in the circle is equal to the distance between the North and South Poles, this circleIt is called "Equator ". On the north and south sides of the Equator, draw many circles parallel to the equator, that is, the latitude circle,It is called a weft. 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 climate, such as the winter in the Equator and low latitude regions,There is no summer in the polar and high latitudes, and the middle and 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 of some circles are called longitude lines. In the year of the planimetric map 1884, the international regulation adopted by the Greenwich Observatory on the outskirts of LondonThe longitude line is used as the start point for calculating the longitude, that is, the longitude is 0 minutes 0 seconds, also known as the "primary meridian ". The east longitude is in the east, with a total of 180 degrees;In the west of the Meridian, 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. CountriesThe 180-degree longitude line is the "International Date change line ". In order to avoid using two different dates in the same region, the international date variation occurs on land.Slightly deviated.Each longitude and latitude can be subdivided into 60 minutes, and each minute is divided into 60 seconds and decimal places in seconds. We can confirm with the cableThe specific location of each place on the earth, and it is displayed on a map or globe. For example, what is the longitude and latitude of Beijing? WeIt is easy to find out from the map that the longitude is 116 degrees 24 points, and the latitude is 39 degrees 54 points. For a vessel sailing in the sea, you only need to test the longitude of its location.To determine the position and Forward Direction of the ship in the ocean. The latitude is 90 degrees. The equator is 0 degrees, arranged to two poles, and the smaller the circle,The higher the level.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. Because all longitude lines are the same length, to measureLongitude selects a starting area. After consultation at the 1884 International Conference, it is decided to pass through the Greenwich royal family on the outskirts of London and the south bank of the river.The meridian line of a major meridian Cross of the Observatory (old site) is the starting Meridian. The primary meridian plane is the starting point.Point plane. The end plane is the plane of the local longitude line. The longitude of a point is the angle between the longitude plane of the point and the primary meridian plane. InOn the equator, the original 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 WestLongitude. 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, and the east longitude is the mostThe longitude is 180 °, and the maximum value of the west longitude is 180 °. The longitude line of the east and west longitude is the same longitude line.180 ° longitude cable.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, from the equator to the south, north, and NorthA value is called the north latitude, and a value to 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. Equator is0 ° weft, the maximum value of the north latitude is 90 °, that is, the northern point; the maximum value of the southern latitude is 90 °, that is, the southern pole.`

Longitude and latitude Interchange

Degree (DDD): E 108.90593 degrees N 34.21630 degrees

How to convert degrees (DDD): 108.90593 degrees to degrees (DMS) Dong Jing 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 does not have a great impact. The error of one second is a few meters. GPS drivers can use the above method to convert the Unit coordinates they need.

Longitude and latitude to meter

The latitude is divided into 60 points, and each point is divided into 60 seconds and the decimal point of the second.

The latitude line is projected on a seemingly horizontal parallel line, but it is actually a circle with different radius. All locations with the same specific latitude are on the same weft.
The latitude of the equator is 0 °, and the planet is evenly divided into the Southern Hemisphere and the northern hemisphere.
Latitude refers to the line angle between a point and the Earth's ball center and the Earth's track surface. Its value ranges from 0 to 90 degrees. The latitude of a point located north of the equator is north latitude, which is recorded as n. the latitude of a point located south of the equator is called south latitude, and it is recorded as S.
The region with the latitude value between 0 and 30 degrees is called the low latitude area, and the region with the latitude value between 30 and 60 degrees is called the middle latitude area, the area with a latitude value between 60 and 90 degrees is called the high latitude area.
The equator, the return-to-south line, the return-to-north line, the Antarctic Circle, and the Arctic Circle are special latitudes.
Length of 1 second at latitude
The total meridian length of the Earth is about 40008 km. Average:
Latitude 1 degree = approximately 111 km
Latitude: 1 = approximately 1.85 km
Latitude 1 second = approximately 30.9 m

Calculate the distance between two points based on the longitude and latitude of any two points on the ball

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.621371192 mile

If only the longitude is processed plus and minus, And the latitude is not processed with 90-latitude (assuming 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

The 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

In practical application, we generally use an individual zip code to find the longitude and latitude of the region center corresponding to the zip code, and then calculate the distance between each other based on these latitudes, to estimate the approximate distance between certain groups (for example, the distribution range of hotel passengers-the latitude and longitude corresponding to the zip code of each passenger and the distance range calculated by the hotel's latitude and longitude ), therefore, it is a useful resource to query such a database by postal code.
Appendix: C #Code:

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 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 = math. round (S * 10000)/10000;
return s;
}

Related Keywords:
Related Article

## E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

## Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

## Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth \$300-1200 USD