0

I'm building a location based application.

Lets say that i have user A and i have a latitude and longitude values of his current location.

I got user B,C,D and thier locations as well.. For the example - user B + D are in a radius of 5km from user A and user C is in 12km radius from user A and I want to know how can i make a function that will tell me that whose near to me by 4/5/6/7km and etc.. If i user A wants users that are 8.5km away from him i will have as a result user B + D and thier distance from user A.

Now.. i know that i can use the Location class and use the distance function to calculate the distance between two users. But the problem is that if i want to calculate that for the radius distance i need to fetch the entire users list from my database and send it to the client to start calculating distances between him and those i fetched from the server. Now i dont want to do that off course if there is a better and more effecient way..

Firstly, I thought off using http request or some mathematical functions to calculate the distance between my users on the server side but the client (Android) offers very good tools to do so , so because of that I am lost of knowing to is the best thing to do.

Thanks head up :)

Ido Magor
  • 544
  • 1
  • 5
  • 14

1 Answers1

0

Hey don't you think that always sending locations of n-1 users to one requesting from server is inefficient and consumes unnecessary bandwidth than sending only few in the radius vicinity? The server can easily do this computation. Think of a scenario where your app user base grows and grows? Then what? Such a computation is always performed on the server.

Also nearly all of the times, server has much more computing power than the client. So even though android tools look lucrative, don't end up using those in a scenario like this.

In terms of tools, there are similar on the server side too ex. the haversine function. Also some databases like mongo also have inbuilt location filters. So this is really worth checking out.

Msk
  • 857
  • 9
  • 16
  • Firstly Msk thanks for the reply. I thought so either but now the question is that i am running a Django server side with postgresql database. Do you know any suitable libraries to do so? – Ido Magor Jan 09 '16 at 09:12
  • Why a library? Check this function http://stackoverflow.com/questions/4913349/haversine-formula-in-python-bearing-and-distance-between-two-gps-points – Msk Jan 09 '16 at 09:42