Showing posts with label proximity. Show all posts
Showing posts with label proximity. Show all posts

Friday, July 28, 2017

Is it possible to detect Android devices laying side by side

Leave a Comment

I am developing an Android application that requires devices to be laid side by side and/or above and below each other.

I know I can use the Nearby API to detect devices "Nearby" however I need something a little more "Finer Grained".

My app needs to be able to identify a device laying either on the left side, above, right side or below. While all devices are laying flat on a table (for instance).

I can find nothing on the web that describes this use case.

Is it possible?

UPDATE

My use case is that I want Android devices to be able to detect any number of "Other Devices" laying either to their left or right. The devices will be laid out horizontally with a "small" gap between each one.

In the same way that you might layout children's lettered blocks to spell out a word or phrase, or numbered blocks to make a sum.

not only should the line of devices be able to detect their immediate neighbours to their left and right the two devices at either end should be able to detect they they are the start and end (reading left to right) of the line.

7 Answers

Answers 1

Using proximity sensors is a likely way to solve your question. TYPE_PROXIMITY will gives the distance from a near by object. TYPE_MAGNETIC_FIELD gives the geomagnetic field strength on x/y/z.

For more read Position Sensors.

Answers 2

An idea, in case it's relevant for your use case:

  • Setup phase
    • start your app on each device in "pairing mode".
    • Each device will show a QR code containing the key required for communicating with the device (for example via Firebase), and screen details: size in pixels. It will also draw a rectangle at the screen boundaries.
    • A different phone, external to this layout will run your app as a "master", taking a picture of the phones from above.
    • Now you need to write an algorithm to identify the screens and their locations, orientation and extract the QR codes for analysis. Not easy, but doable.
  • Interaction phase
    • now all the phones (this should work on more than two phones) can collaborate screens to show parts of the same movie, for example.

Answers 3

  1. Making your own Mock GPS (Local PS to be exact). I don't have a link for this but its definitely possible. Check out how GPS works to get an idea. Wifi and Bluetooth are signals. but you know what else is a signal?

A: SOUND

make each phone make a large beep in turn and measure audio strength using receivers. This might work better than wifi/bluetooth. once you measure relative distances between every pair of phones, it only takes a good algorithm to find relative positions

  1. A Possible Alternative Solution : use image processing. Get something like OpenCV for Android and setup one phone as a master. This will work only for a 2D Layout.

  2. Another "idea" - use the cameras. Stick A board on top of your surface with 4 QR codes in each corner. (This will help identify the edges and orientation of your phone). If you're looking for a 3D layout and the phones have sufficient in-between space, you could stick a QR behind every phone and show a QR on the screen of every phone.

All of these are solutions. Maybe you can use individual ones. Maybe you can use a combination. who knows.

Answers 4

Seems not, if You have only 2 devices, but if You have external sources (with known position) of any signal (audio, vibrate, BT or WiFi radio, etc.), which can be detected by devices with adequate accuracy, and devices time is synchronized, You can do this comparing time of signal start (or signal strength) on both devices like on this picture:

Example

Or, if You can add some sensors to one of devices, You can create "other device locator", for example like this sound locator.

UPDATE

In a updated formulation, the issue is also not solvable: it's possible to determine which two devices are at the edge, but you can not determine which one is on the left and which is on the right side. It is necessary that at least one device knows that it, for example, is leftmost - then other devices, for example, generates a sound, the others receive it and determine their order according to the difference in arrival time. But the anchor point and synchronization of time are necessary.

Answers 5

By understating your use case, it is possible to find number of devices surrounded by host device, using Nearby Api, other techniques. But find how many devices each side!!! I don't think it is possible with the current mobile hardware and technology. Because, by considering all factors, magnetic sensors are only the least possible solution. But the current mobiles have no such capability.

The following point I made based on above answers. TYPE_ACCELEROMETER, TYPE_LINEAR_ACCELERATION, TYPE_MAGNETIC_FIELD, TYPE_ORIENTATION these sensors are react to the magnetic field around the device (compass react to the magnet). You can try an app using TYPE_MAGNETIC_FIELD, test how it will react to other device when close to it (I think it will react).

But the point I am trying to make here is, if you put three devices to once side and 4 devices to other side, the MAGNETIC_FIELD sensor reads relative magnetic field. So we can't identify how may devices each side, Until unless you have made some scientific calculations.

The second point is, some one suggested TYPE_PROXIMITY sensor, but it is not meant to serve this purpose. Current mobiles, measures the proximity of an object in cm relative to the view screen of a device. This sensor is typically used to determine whether a handset is being held up to a person's ear.

Another least possibility is using location sensor, it can identify the coordinates relative to your device coordinates, you communicate between each device coordinates with host using NFC. But the problem is, your use case says those devices are very close to each other, so it is not measurable distance using location service.

To conclude, it is not possible to identify number of each devices each side of a host device, with the current mobile hardware. It will can archived by using external sensor that will extends the mobile capability. For example, a phone case that equipped with such a capability, this will open window to other use-cases and application as well.

Answers 6

I think a way but it may require a a bit work. First check if 2 devices are laying by getting device orientation and using accelerometer or rotation vector to check pitch, roll, etc.

When you are sure that they are laying send data from one device from one to another using BT or wifi. Data should include send time. Check retreive time on other device also you should check for latency for sending and retreiving data. If you can have a noticible time differences in ms for small distance differences between devices it would be easy to check how approximately close they are. Also you may ask users to hold their device 1 meter or fixed distance from each other to get a time of travel for BT or wifi signal you send to other.

Answers 7

If you could choose an 'object of reference', perhaps you can solve this. Since left, right, top and bottom are relative, devices should be aware of something that is locally stationary. The devices will try to locate this 'object of reference' and once they know where they are with respect to the latter, they could share this data with each other to figure out their orientation with each other. Just like GPS tries to find a satellite, and then figures out its location, in the same manner, if a device tries to find itself with respect to a locally stationary object(by the means of image processing for example), your use case could be achieved.

Read More

Saturday, May 7, 2016

Proximity alert for locations saved at server

Leave a Comment

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?

4 Answers

Answers 1

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.

Answers 2

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".

Answers 3

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.

Answers 4

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)

Read More