Zero
Zero

Reputation: 453

Distance between two mobile devices in Javascript (Ionic)

For one of my projects, I'm currently wanting to build an Ionic application to code once for both iOS and Android platforms. I'm looking for a way to measure the distance between two mobile devices. One device should be placed into a specific location, and the other one should be detected when it enters the range of the first device (or more specifically the location where the first device is).

Device 1 at a specific location will be connected to the internet, same for the device 2 visiting the location.

I've already read a lot of different implementations, but most of the time it requires native code either for Android, or for iOS.

Here are the solutions I've already found :

I'm actually running out of ideas. The implementation should be in Javascript to code a quick prototype so options are limited.

I've read a post on StackExchange : Stack, but the problem is that no implementation is described.

In other terms, I want a check-in system to know that device 2 went on the location of device 1. Even with an exchange between an API requesting our servers, how could we be sure that two devices are closed by or at least device 2 went at a specific location?

EDIT & NEWS

To give more options to people who might face the same situation, I got in touch with someone working at Microsoft and on a project called: ThaliProject which you can find on Google which is a PeerToPeer library to communicate between mobile devices. But it's not suited to this problem :

Unfortunately Thali isn't going to solve your problem. :( We depend on Bluetooth 4.2 support on Android (so we can be both a BLE central and peripheral).

Bluetooth also won't work if you need things to work between an Android and iOS device because Apple uses a proprietary variant of Bluetooth that doesn't work.

Now BLE does work between Android and iOS. And while many Android phones can't be peripheral, most of them can be central.

Another possibility that different folks are playing around with is sound. Something like https://developers.google.com/nearby/messages/overview?hl=en. A number of groups have been experimenting with local discovery via ultrasonic communication. Just send the challenge and get the response over ultrasonic and you have proven that devices 1 and 2 are very close to each other.

I found by chance a JavaScript library called: SonicNet.JS to be able to send data and strings by ultrasounds, but I'm actually struggling to make it work on my computer. This might be a solution and avoid interoperability problems.

Upvotes: 18

Views: 4660

Answers (2)

Hong
Hong

Reputation: 546

how about Time of Fly from wifi device? Basically, the app on device A needs to send a signal round. Device B picks it up and return a signal with a signature. Device A receives it and calculates the distance based on fly of time.

Or how about using here's API? https://indoor.here.com/#/. The idea is gps + high precision map. I know you thought about gps already. but hd map gives you a way to validate the gps info the device receive so as to address your security concern.

Upvotes: 0

L. CWI
L. CWI

Reputation: 962

You may use the Bluetooth Low Energy plugin for Cordova (https://github.com/evothings/cordova-ble). It is mainly working for Android and iOS.

Of course the devices should support BLE but it is the case of numerous new smartphones.

You can start by scanning around you with evothings.ble.startScan(success, error) and then use the RSSI and txPower values to get the distance between devices.

Upvotes: 0

Related Questions