Function for finding the distance by latitude and longitude

Source: Internet
Author: User
This is a known distance between two points. Can you see if it is helpful?

Hope it will be helpful to you!
'----------------------------------------------------------------------
'The known longitude and latitude Distance Function
'----------------------------------------------------------------------
Function countdistance (byval lon1 as double, byval LAT1 as double, byval lon2 as double, byval LAT2 as double) as double
Dim D as double
Dim A1, A2, B1, B2 as double
A1 = LAT1 * 0.0174532925194
A2 = LAT2 * 0.0174532925194
B1 = lon1 * 0.0174532925194
B2 = lon2 x 0.0174532925194
Countdistance = arccos (math. cos (A1) * Math. cos (A2) * Math. cos (B1) * Math. cos (B2) + math. cos (A1) * Math. sin (B1) * Math. cos (A2) * Math. sin (B2) + math. sin (A1) * Math. sin (A2) * 6371

End Function

Public Function arccos (byval X as double) as double
If CSTR (x) = "1" then
Arccos = 0
Exit Function
Elseif CSTR (x) = "-1" then
Arccos= 3.14159265358979
Exit Function
Else
Arccos = ATN (-x/sqr (-x * x + 1) + 2 * ATN (1)
End if
End Function

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.