Working on a small web application, I have a user table in which user details is stored along with latitude and longitude of their current locations.
A new user registers, he is shown the distance of all the users from where he currently is.
I am doing it using the haversine formula.
My problem is how do I proceed on doing this?
How can I do this on the fly? Or do I need to calculate all the user distances when the user registers and save it?
Should cater for sorting: i.e shortest distance first.
If the number of users is going to be very large (or unbounded) then you may run into trouble.
Calculating this up-front might require quite a bit of storage. But calculating on demand might require a large amount of server CPU time.
Use MySQL to do the geo-sorting. http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL
Consider calculating distances for only a small subset of other users.