Search code examples
pythonrdbmsgeospatialcoordinate-systems

How to calculate and store Lat/Long data for real time web app?


I am designing an app that will keep track of all user's lat/long. For each user it will calculate the distance between all other users in a city. I will be using python.

For example: My client will update a database with its long/lat every x seconds. Each time it updates it will have to recalculate the distance between itself and all other users that are logged on.

My plan was to split up cities into their own tables, so as to keep the data set and calculations smaller. But the more I think about this idea gets worse and worse. I don't think it would scale at all if there were any signficant amount of traffic. People would have to be confined to a major metropolitan area if they want to use the app which would limit the user base.

so my question is:

Is there a storage backend that is optimized to do these calculations? I have just heard about PostGIS this morning but from what I have read it seems like it might be overkill? All I plan on doing is calculating the distance between lat/long's. Thank you


Solution

  • There is "aviation formulary". Look there under "distance between points".

    Here's the Equirectangular Approximation which is a hair faster.

    Angles (la1, lo1), (la2, lo2) are in radians; you must convert from degrees.

    The response, c, similarly, is in radians. You don't want degrees, but want statute miles or km. For that, multiply by the earth's mean radius: 6,378.1 kilometers, 3,961.3 miles

    Equirectangular Approximation