how to get the distance between to points on earth in Swift?

What is the distance between points A and B on the surface of the earth?

  • Calculate the distance between points A and B on the surface of the earth A: Latitude 25° 47’ 42” Longitude 80° 16’ 4” B: Latitude 51° 27’ 36” Longitude 0° 26’ 46” I know that if you’re clever enough, there are various ways to find the answer to this question. Preference for best answer will be given to answers with a mathematical approach that can be generalized. You may take the radius of the earth as 4000 miles.

  • Answer:

    Okay, let R = 4000 miles, x1 = 25° 47’ 42” N, y1 = 80° 16’ 4” W, x2 = 51° 27’ 36” N, y2 = 0° 26’ 46” W (notice that I put in N and W), then we have the great circle distance: D = R ArcCos(Cos(x1)Cos(x2)Cox(y1-y2) + Sin(x1)Sin(x2)) which comes to about 4,463 miles. Using Google's great circle mapper and calculator (see link) confirms this. The brute force method for computing this is to find the cartesian coordinates for point A and B, and then the angle they form with the origin. Addendum: Maybe I should have added that the brute force method can be used to derive the great circle formula given.

Dr D at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

w - longitude, n - latitude Point r = (w, n) in spherical coordinated has (R*sin(w)*cos(n), R*cos(w)cos(n), R*sin(n)) cartesian coordinates. cos(phi) = (r1, r2)/|r1||r2 = sin(w1)*cos(n1) * sin(w2)*cos(n2) + cos(w1)*cos(n1) * cos(w2)*cos(n2) + sin(n1)*sin(n2) Distance D = phi*R = R*arccos(sin(w1)*cos(n1) * sin(w2)*cos(n2) + cos(w1)cos(n1) * cos(w2)cos(n2) + sin(n1)*sin(n2)) D= R*arccos(cos(n1)*cos(n2) * cos(w2 - w1) + sin(n1)*sin(n2))

Alexey V

7512.147 kilometers; 4667.832 miles

Steve b

Difference of latitude between A and B = 25degree-39'54" . Now this is length of the arc on spherical earth surface. Therefore length of this arc = Radius x angle in radian. = 4000x (25.665xPi/180) = 179.175 miles

Pramod

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.