JoshLittlewood
JoshLittlewood

Reputation: 21

How to detect nearby android devices using the same app

So basically I have made a few small apps in the past, but this is my first 'proper' app.

One of the main features of the app, and the bit that I am struggling with is that I need to be able to populate a ListView with all of the other users logged into the app, however I only want to display users that are within a set distance, for example 10 meters.

I tried using Bluetooth to achieve this, however that didn't work. I would now like to use location services to do this.

My idea is to have to app send the location of the device to an external server every few minutes and then all other devices can run a function that compare their location to others found on this server.

Does anybody know how I could go about achieving this, or know of any tutorials that cover a simpler topic. Thank you

Upvotes: 0

Views: 4644

Answers (1)

jt000
jt000

Reputation: 3236

Disclaimer: I'm not an android developer, but this seems like a design issue not a implementation issue so hopefully my comments below might be of some use...

I don't think there's an API that you can just set to "true" to get this functionality, so I think you're going to have to custom craft all the moving parts (and there are a couple). I would think the general process would be something like:

On the client:

  1. User on client logs in to server with some sort of identity (i.e. "[email protected]")
  2. Every X minutes the client app gets the current location (i.e. "100N 90E") and sends it up to a server
  3. Every X minutes the client polls the server to see who is within 10 miles (i.e."[email protected]", "[email protected]")

On the server:

  1. Needs some sort of authentication endpoints for getting a user's identity
  2. Needs an endpoint for users to register their location ("[email protected] is at 100N 90E")
  3. Needs a service to find out how far each user is from each other
  4. Needs an endpoint to return the users within X miles (list generated from #3)

Each one of these steps shouldn't be difficult on their own and you can actually get pretty nuts with the distribution algorithm on server step #3 if you wanted to.

Some questions you can ask yourself are:

  • "How do I set up a server to listen for HTTP requests?" - Take a look into Node.JS for a simple solution
  • "How do I get a user's location in android?" - Easy google search finds plenty of documentation
  • "How do I write a service to continuously perform actions?" - Node.JS would again help with this
  • "Where will I store user's locations and their distances from each other?" - You can look into a NoSQL option like CouchBase or MongoDb. Or you could use MySQL for a more structured database.

Hope this helps...

Upvotes: 6

Related Questions