Proximity alert for locations saved at server
Asked Answered
J

5

12

I did some search but could not find a suitable answer.

My App should compare with multiple locations for proximity. This means I will not be able to save all the locations into my app to confirm the proximity using locationManager. I want the proximity confirmation to be done in the server

What would be the best way to implement this?

Would it be sensible if the app asks for proximity confirmation every time the devices moves around?

Jadejaded answered 26/4, 2016 at 22:24 Comment(2)
What kind of latency are you expecting from the time the device enters the proximity to the time the device gets notified? Also, do you expect more than 100 locations to calculate proximity to within a 5 mile radius?Soubise
Latency is not a top priority quality issue, bur hopefully get response within a few secs. Also I am expecting many locations within 5 mile radius, and that location may change dynamically.Jadejaded
N
9

I would try a different approach, since location updates from GPS are made once per second, and I don't think it's a good idea to ask the server each second for proximity if you have a large amount of devices.
Think of this idea -

  1. Get the device's initial location and send it to the server.
  2. Decide on a sensible radius that the device will stay within it for the next 5-10 minutes. Also make sure that you don't have "too many" points in that radius, or you can narrow the radius in that case. It's up to you to decide the radius and the number of points, depending on your usage, number of points etc.
  3. Send form the server all the locations within that radius to the device.
  4. Let the device calculate the proximity by itself.
  5. When the device moves out of the initial radius - update the server and get the new relevant locations. This can be done easily - call the radius r. Save the initial location of the device, and calculate the distance between the current and initail location. When it is "close enough" to r - update the server.
Nougat answered 1/5, 2016 at 15:29 Comment(0)
A
5

In your case, simply, you can send the received locations to your server and then make required calculations on server. But don't forget that you will be dealing with those questions

  • How many devices send location to server ?
  • How frequently each device send location to server ?

Also the responsibility of detecting a device has entered an area on the server

I think you can reduce the complexity of the all things by using geofencing api, link

  • No need to send each location to server.
  • Each device individually detects itself has entered or exited an area.

EDIT

Otherwise you will be doing entered/exited calculations on server for unlimited count of device, whenever each device's location has changed.

Before we were doing similar thing in my previous company, calculating enter/exit time and enter durations. but via real gps devices on buses

  • We have almost 100 points(geofence) in city. So you can think that those points are on a few routes

  • Each gps device on bus is sending location to server periodically.

  • When the bus has finished it's route, server reviews device's all received locations on the route.

  • Compares each geofence with each location of bus.

This is the real scenario. You can call it "server based geofencing".

Apollyon answered 1/5, 2016 at 10:7 Comment(1)
Geofencing has the limitation to have only 100 locations. I want to have no limit to my location detection. Also to answer your question > Q1 How many devices send location to server? : A1 Unlimited > Q2 How frequently each device send location to server? : A2 When ever the device is moving.Jadejaded
M
5

You could do a simple k-d tree implementation on the server side to store the coordinates.

Send the coordinates of the device over, which can be determined at whatever interval you need. If it's every 5 seconds, or 10 seconds it doesn't really matter. This will mainly be decided by the minimum distance between each of the coordinates/radius. If they're closer, you may need to update it more frequently.

Using the k-d tree finding the nearest neighbor would be O(log(n)). However, you make a slight modification where you can start adding the nodes to a list as long as they are within the certain radius of your device coordinates. In fact if you store it locally as a k-d tree as well then you can pick the furthest nodes in O(log(n))

Now on the second update when the device location is sent again, you can quickly update it since you have the existing locations. Say you move in the x direction by 5. You can drop the points that are now outside of the radius at x - 5. The new proximity, you do the same nearest neighbor search, adding in nodes as they're within the radius, but this time starting with the cached nodes closest to the direction you are moving in.

Combining that with an interval tree for radiuses. So say 0 to 1, 1 to 2, 2 to 3, as your intervals. You can pick out everything within a certain radius in O(log(n)) time as well. Those should be pointers to nodes in the k-d tree. That would simplify the radius calculations and finding the location if you're willing to sacrifice some memory for efficiency.

M answered 4/5, 2016 at 10:2 Comment(0)
D
5

For a "fast" way to implement it on the server side you can use the mondodb $near geospatial query.

https://docs.mongodb.org/manual/reference/operator/query/near/

While on the mobile side you can use the minDistance property for the location updates. You can set it to a reasonable distance 20m/50m depending on the average distance between your locations.

http://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates(java.lang.String,%20long,%20float,%20android.location.LocationListener)

Disoperation answered 4/5, 2016 at 20:22 Comment(0)
P
0

There is a free service for this purpose -> Radar

You can register unlimited circle or polygon geofence, and register your user in app for tracking that user. When user entered in one geofence Radar send a notification to your server and send below data to you:
User ID, Geofence ID that user entered or exit, Confidence (low, medium, high) used for geofence that has overlap.
You can use this SDK in only 10 minutes.

Politesse answered 8/5, 2017 at 14:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.