Calculate the distance based on the latitude and longitude of two points
How are these longitude and latitude lines determined? The earth is constantly rotating around the earth's axis (the earth's axis is an imaginary line passing through the north and south poles of the earth and the center of the earth). Draw a large circle perpendicular to the earth's axis in the middle of the earth, so that every point on the circle is equal to the north and south poles. This circle is called the "equator". On the north and south sides of the equator, many circles parallel to the equator are drawn, which are "latitude circles"; the segments that make up these circles are called latitude lines. We set the equator at latitude zero, and each is 90 degrees south to north. The ones south of the equator are called the south latitude, and the ones north of the equator are called the north latitude.
The North Pole is 90 degrees north latitude, and the South Pole is 90 degrees south latitude. The height of latitude also marks the hot and cold climate, such as there is no winter in the equator and low latitude areas, no summer in the poles and high latitude areas, and the four seasons in the mid latitude areas.
Secondly, from the North Pole to the South Pole, many large circles perpendicular to the earth's equator in the north and south directions can be drawn, which is called "vera circle"; the segments that make up these circles are called meridian lines. In the 1884 AD, the international regulations used the meridians of the Greenwich Observatory in the suburbs of London, England as the starting point for calculating longitude, that is, the longitude zero degree zero minutes and zero seconds, also known as the "primary meridian". To the east of it is the eastern longitude, with a total of 180 degrees;
To the west of it is the western longitude, with a total of 180 degrees. Because the earth is round, the meridians at 180 degrees east longitude and 180 degrees west longitude are the same meridian. The 180-degree longitude line is designated as the "international date change line". In order to avoid the use of two different dates in the same area, the international date change line will deviate slightly when encountering land.
Each longitude and latitude can be further subdivided into 60 minutes, and each minute is further divided into 60 seconds and a decimal number of seconds. Using longitude and latitude lines, we can determine the specific location of each place on the earth and represent it on a map or globe. For example, what is the latitude and longitude of Beijing? It is easy to find from the map that it is 116 degrees 24 minutes east longitude and 39 degrees 54 minutes north latitude. Ships sailing in the sea only need to measure the longitude of their location
When you come out, you can determine the position and direction of the ship in the ocean. There are 90 degrees in total. The equator is 0 degrees and is arranged toward the poles. The smaller the circle, the greater the degree.
The horizontal line is the latitude, and the vertical line is the longitude.
Of course, it can be calculated, quadratic equations.
Longitude and latitude are both angles. Longitude is a bihedral angle, the angle between the two meridian planes. Because all meridians are the same length, in order to measure longitude, a starting point surface was selected, after consultation in 1884, it was decided to use the meridian line of a major meridian cross thread passing through the Royal Observatory of Greenwich (formerly site) on the suburbs of London, England, on the south bank of the Thames River as the starting meridian line, called the prime meridian. The prime meridian plane is the starting point plane, and the end point plane is the local meridian plane. The longitude of a certain point is the angle between the meridian plane where the point is located and the prime meridian plane. Measuring on the equator, the meridian plane of the prime minister is used as the starting point, and the measurement is eastward and westward respectively. The value to the east is called the eastern longitude, and the value to the west is called the western longitude. It can be seen from this that the longitude of a place is the direction and angular distance of the place to the prime meridian. The prime meridian is 0° longitude, the eastern longitude is the highest
The maximum value is 180°, the maximum value of western longitude is 180°, and the 180° meridians of the east and west longitudes are the same meridians, so they are not divided into east longitude or west longitude, but are collectively called 180° meridians.
The latitude is a line-face angle. The starting surface is the equatorial plane, and the line is the local ground normal. The so-called normal line is a line perpendicular to the surface of the reference flat sphere.
The latitude of a certain place is the angle between the normal line of the place and the equatorial plane. The latitude is measured on the local longitude line, from the equator to the south and north. The northward magnitude is called the north latitude and the southward magnitude is called the south latitude. It can be seen from this that the latitude of a land is the direction and angular distance of the land to the equator. The equator is a 0° latitude line, with the maximum value of the north latitude being 90°, that is, the North Pole; the maximum value of the south latitude being 90°, that is, the South Pole. Latitude and longitude interchange
Degree (DDD): E 108.90593 degrees N 34.21630 degrees
How to convert degrees (DDD):: 108.90593 degrees into degrees minute and second (DMS) E east longitude E 108 degrees 54 minutes 22.2 seconds? The conversion method is to unchange the 108.90593 integer bits into 108 (degrees), use 0.90593*60=54.3558, take the integer bits 54 (minutes), 0.3558*60=21.348 and then take the integer bits 21 (seconds), so it is converted into 108 degrees 54 minutes 21 seconds.
The same method of converting degrees to degrees (DMS): E 108 degrees 54 minutes 22.2 seconds into degrees (DDD) is as follows: 108 degrees 54 minutes 22.2 seconds = 108+ (54/60)+ (22.2/3600)=108.90616 degrees
Because the decimal places are retained during calculation, there are certain errors in the forward and reverse calculations, but the error impact is not very large. The error of 1 second is just a few meters. GPS riders can convert the unit coordinates they need using the above method.
Convert latitude and longitude into meters
The latitude is divided into 60 minutes, and each minute is divided into 60 seconds and a decimal number of seconds.
The latitude line is projected on the graph that looks horizontally parallel lines, but is actually circles of different radii. All positions with the same specific latitude are on the same latitude line. The equator has a latitude of 0°, dividing the planet into the southern and northern hemispheres. Latitude refers to the line-face angle formed by a point connecting the line between the center of the earth and the equatorial plane of the earth, and its value is between 0 and 90 degrees. The latitude of the point located north of the equator is called the north latitude, which is recorded as N, and the latitude of the point located south of the equator is called the south latitude, which is recorded as S.
Areas with latitude values between 0 and 30 degrees are called low latitude areas, areas with latitude values between 30 and 60 degrees are called mid-latitude areas, and areas with latitude values between 60 and 90 degrees are called high latitude areas.
The equator, Tropic of Cancer, Tropic of Cancer, Antarctic Circle and Arctic Circle are special latitudes.
Length of 1 second in latitude
The total length of the Earth's meridian is about 40,008km. average:
Latitude 1 = approximately 111km
Latitude 1 point = approximately 1.85km
Latitude 1 second = approximately 30.9m
Under WGS84 coordinate system (usually we use coordinate system in GPS)
If it is the latitude and longitude coordinates of WGS1984 commonly used in China, 1 second is equivalent to 33 meters. The details are as follows:
Longitude 1 degree = 85.39km
Longitude 1 point = 1.42km
Longitude 1 second = 23.6m
Calculate the distance between two points based on the latitude and longitude of any two points on the earth
The earth is a nearly standard ellipsoid with an equatorial radius of 6378.140 kilometers, a pole radius of 6356.755 kilometers, and an average radius of 6371.004 kilometers. If we assume that the earth is a perfect sphere, its radius is the average radius of the earth, which is denoted as R. If the 0-degree longitude is used as the basis, the surface distance between these two points can be calculated based on the latitude and longitude of any two points on the earth's surface (the error caused by the terrain on the surface of the earth to the calculation is ignored here, it is only a theoretical estimate). Suppose the latitude and latitude of the first point A is (LonA, LatA), the latitude and latitude and latitude of the second point B is (LonB, LatB). According to the reference of the 0-degree longitude, the positive value of the longitude in the east is (Longitude), the negative value of the longitude in the west is (-Longitude), the 90-latitude value of the north is (90-Latitude), and the 90+latitude value of the south is (90+Latitude). Then the two points after the above treatment are counted as (MLonA, MLatA) and (MLonB, MLatB). Then, based on triangle derivation, the following formula for calculating the distance between two points can be obtained:
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 kilometers are used as the radius, then Distance is the unit of kilometers. If you want to use other units, such as mile, you also need to convert units. 1 kilometers = 0.621371192mile
If only the longitude is treated with positive and negative, and not 90-Latitude (assuming that they are all in the northern hemisphere and only Australia has application significance in the southern hemisphere), then 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 of the trigonometric function are both radian values, the formula can also be written:
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 applications, it is generally to search for the latitude and longitude of the area center corresponding to the zip code through the individual's postal code, and then calculate the distance between each other based on these latitude and longitude, thereby estimating the approximate distance range between certain groups (such as 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 latitude and longitude of the hotel - etc.). Therefore, a database such as querying latitude and longitude through the zip code is a very useful resource.
Attachment: C# code:
private const double EARTH_RADIUS = 6378.137;//Earth radius
private static double rad(double d)
{
return d * / 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 * ((((a/2),2) +
(radLat1)*(radLat2)*((b/2),2)));
s = s * EARTH_RADIUS;
s = (s * 10000) / 10000;
return s;
}
Principle: The Earth's equator walks around the earth in a total of 40075.04 kilometers, and the @ circle is divided into 360°, and there is 60 for every 1° (degree). The length of each degree and a second on the equator is calculated as follows:
40075.04km/360°=111.31955km
111.31955km/60=1.8553258km=1855.3m
And every minute has 60 seconds, and every second means 1855.3m/60=30.92m
The calculation formula for any two points is
d=111.12cos{1/[sinΦAsinΦB ten cosΦAcosΦBcos(λB—λA)]}
Among them, the longitude and latitude of point A are λA and ΦA, respectively, and the longitude and latitude of point B are λB and ΦB, respectively, and d is the distance.