views:

223

answers:

3

I'm creating an application that will tell a user how far away a large number of points are from their current position.

Each point has a longitude and latitude.

I've read over this article http://www.movable-type.co.uk/scripts/latlong.html

and seen this post http://stackoverflow.com/questions/837872/calculate-distance-in-meters-when-you-know-longitude-and-latitude-in-java

There are a number of calculations (50-200) that need carried about.

If speed is more important than the accuracy of these calculations, which one is best?

+1  A: 

The two links that you posted use the same spherical geometry formula to calculate the distances, so I would not expect there to be a significant difference between their running speed. Also, they are not really computationally expensive, so I would not expect it to be a problem, even on the scale of a few hundred iterations, if you are running on modern hardware.

VeeArr
+3  A: 

this is O(n) Dont worry about performance. unless every single calculation takes too long (which it isnt).

Imre L
+2  A: 

As Imre said this is O(n), or linear, meaning that no matter how the values differ or how many times you do it the calculations in the algorithm will take the same amount of time for each iteration. However, I disagree in the context that the Spherical Law of Cosines has less actual variables and calculations being performed in the algorithm meaning that less resources are being used. Hence, I would choose that one because the only thing that will differ speed would be the computer resources available. (note: although it will be barely noticable unless on a really old/slow machine)

Verdict based on opinion: Spherical Law of Cosines

GEShafer