Watch, Follow, &
Connect with Us

Developer Tools Community.

Thread: Calculating distance between two points, using latitude longitude? Replies: 1 - Last Post: Jul 27, 2015 1:27 PM Last Post By: bernard roussely
 Posts: 5 Registered: 7/30/15
 Calculating distance between two points, using latitude longitude? Posted: Jul 13, 2015 11:49 PM I am trying to calculate distance between two points using java code, I have written a code but it is not working. I have checked various forums to get the resolution to my query. I have found [java questions and answers](http://findnerd.com/askquestion/java) specifically posted on this forum and hope I'll get a solution from the member of this community. Here is code final double RADIUS = 6371.01; double temp = Math.cos(Math.toRadians(latA)) * Math.cos(Math.toRadians(latB)) * Math.cos(Math.toRadians((latB) - (latA))) + Math.sin(Math.toRadians(latA)) * Math.sin(Math.toRadians(latB)); return temp * RADIUS * Math.PI / 180; Posts: 106 Registered: 2/8/05
 Re: Calculating distance between two points, using latitude longitude? Posted: Jul 27, 2015 1:27 PM in response to: Ranjeet Kumar Hello, This web site has all the formulas: http://www.movable-type.co.uk/scripts/latlong.html I have done this on Android in C++ : float __fastcall TWhateverForm::ComputeDistance(TLocationCoord2D A, TLocationCoord2D B) { const int R = 6371000; // metres float phi_1 = DegToRad((const float)A.Latitude); float phi_2 = DegToRad((const float)B.Latitude); float delta_phi = DegToRad((const float)(B.Latitude - A.Latitude)); float delta_lambda = DegToRad((const float)(B.Longitude - A.Longitude));   float arc = sin(delta_phi/2) * sin(delta_phi/2) + cos(phi_1) * cos(phi_2) * sin(delta_lambda/2) * sin(delta_lambda/2); float angle = 2 * atan2(sqrt(arc), sqrt(1 - arc));   return (R * angle); } Regards, bernard Legend Helpful Answer (5 pts) Correct Answer (10 pts) Server Response from: ETNAJIVE02