Reputation: 4727
I have an app that allows a user to transmit their location to a server. What I am trying to do is have the user press a button that will send a push notification to anyone with the app within lets say a 3 mile radius. Can someone give me an overview of how I can accomplish this.
The only way I could think of doing this is publishing the gps coords to a server. Then when the user presses "Send notif" a message gets sent to the server, then the server does some complex proximity search based upon the location and then returns the values to the user.
My problem is, I have no server-side experience and have no idea how to program a GPS search algorithm on the server.
Is there a way for me to do what I want without having to write code on a server? I am able to use Parse to store the GPS coordinates. I'd like to keep my server code to simply storing and retrieving values and handle everything else client side.
Thoughts?
Upvotes: 3
Views: 6176
Reputation: 402
If you really want to put all the load on the client (iOS) side:
Then
//otherUsers is the NSArray or NSSet with custom objects
//currentLocation is the users current location
for(MYCustomUser * otherUser in otherUsers) {
if([currentLocation distanceFromLocation:[otherUser location]] < 4829) { //4828 == 3 Miles in Meters, so 4829 is 3 Miles + one Meter
//send msg to server to perform push notf. to user
}
}
Done...
you should put this in a NSOperationQueue so that is can run in background an is not blocking the device
But as bbarnhart said... it's not very wise to put all this on a device.
Upvotes: 0
Reputation: 6710
Each device should send their GPS coordinates to the server periodically. I think you already have this step. The next step is to find devices that are near each other. This is fairly simple.
Distance Between Two Latitude and Longitude Points
However, if you have millions of devices, it will be a problem of scale if you compare each update to all the other devices. You might bucket the devices to a certain area. For example, you might bucket the updates into 100 square mile areas. When an update comes in you need to only compare to those devies in that bucket plus adjacent buckets if they are near the edge. This is just top of the head analysis but hopefully it will point you in the right direction.
Upvotes: 3