Calculate the distance between two GPS coordinates

Source: Internet
Author: User

Scenario: the longitude and latitude coordinates of two GPS points are known. Calculate the distance between two points.

1.Distance/latitude relationship

GPS: 22.514519, 113.380301

GPS: 22.511962, 113.380301

Distance: 284.6439379583341 

Jl_wd = 284.6439379583341/(22.51451-22.511962)

= 111712.69150641055729984301412873 (meters/degree)

2.Distance/longitude relationship

GPS: 22.514866, 113.388444

GPS: 22.514866, 113.379378

Distance: 932.2997762326453

Jl_jd = 932.2997762326453/(113.388444-113.379378)

= 102834.74258026089786013677476285 (meters/degree)

3. Cut-off Theorem

 

Pythagorean theorem: a2 + b2 = c2

 

 


After knowing the coordinates of A and B, you can obtain the absolute value of the latitude difference between A and B.

Wd_c = | (N1,-N2) |

Absolute Value of the longitude difference between point A and point B

Jd_c = | (E2-E1) |

Knowing the relationship between longitude, latitude and distance, and the longitude difference and latitude difference between point a and point B, you can find the length of B and the length of, after finding a and B, you can use the stock theorem of the straight triangle to find the length of the c side, that is, the distance between point a and point B.

B = wd_c * jl_wd

A = jd_c * jl_jd

C = √ (a2 + b2)

 

C # implementation code:

 

Calculate the distance between two GPS coordinates

/// <Summary>
/// Calculate the distance between two GPS coordinates
/// </Summary>
/// <Param name = "n1"> latitude coordinate of the first point </param>
/// <Param name = "e1"> longitude coordinate of the first vertex </param>
/// <Param name = "n2"> latitude coordinate of the second point </param>
/// <Param name = "e2"> longitude coordinate of the second vertex </param>
/// <Returns> </returns>
Public static double Distance (double n1, double e1, double n2, double e2)
{
Double maid = 102834.74258026089786013677476285;
Double maid = 111712.69150641055729984301412873;
Double B = Math. Abs (e1-e2) * jl_jd );
Double a = Math. Abs (n1-n2) * jl_wd );
Return Math. Sqrt (a * a + B * B ));

}

 

 

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.