Algorithm and verification of distance between two coordinates

Source: Internet
Author: User
After reading the latitude and longitude distance between two points, it is said that it was obtained from Google. Algorithm So I decided to verify it.
East to west to a VB Code Is found to be correct through computation.
The two coordinate points 30,120 and 31,121 are used for verification, which is very similar to the calculation result in MapInfo.
Later, we calculated the coordinate system directly as a Cartesian coordinate system, and found that the error was very large.
Therefore, we still use the Cartesian coordinate system method to calculate the latitude and add a 0.86 parameter, which is similar to the result.
If you do not upload files, paste the Code directly. The Code is as follows: (five texts and three buttons)
Const Earth_radius = 6378.137
Const Pi = 3.1415926535898

Function Rad (byval d As Double ) As Double
Rad = D * Pi / 180
End Function

Function Getdistance (LAT1 As Double , Lng1 As Double , LAT2 As Double , Lng2 As Double ) As Double
Dim Radlat1 As Double , Radlat2 As Double
Dim A As Double , B As Double , S As Double , Temp As Double
Radlat1 = Rad (LAT1)
Radlat2 = Rad (LAT2)
A = Radlat1 - Radlat2
B = Rad (lng1) - Rad (lng2)
Temp = Sqr ( Sin ( / 2 ) ^ 2 + Cos (Radlat1) * Cos (Radlat2) * Sin (B / 2 ) ^ 2 )
S = 2 * ATN (Temp / Sqr ( - Temp * Temp + 1 )) ' No arcsin function. I found one online.
S = S * Earth_radius
Getdistance = S
End Function

Private Sub Commandmediaclick ()
Text5.text = STR (getdistance (Val (text1.text), Val (text2.text), Val (text3.text), Val (text4.text )))
End sub

Private Sub Command2_click ()
Text5.text = STR (( Sqr (Val (text3.text) - Val (text1.text )) ^ 2 + (Val (text4.text) - Val (text2.text )) ^ 2 )) * 111.3199338 )
End sub

Private Sub Command3_click ()
Text5.text = STR (( Sqr (Val (text3.text) * 0.86 - Val (text1.text) * 0.86 ) ^ 2 + (Val (text4.text) - Val (text2.text )) ^ 2 )) * 111.3199338 )
End sub

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.