Distance between two mobile devices in Javascript (Ionic)
Asked Answered
V

2

18

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 :

  • Bluetooth: Every cellphone has Bluetooth, so it should not be hard to be able to detect once a phone is close to another one, but it means pairing with another device, and it's not really possible to measure the distance between two devices.
  • iBeacons and BLE: We would like to avoid having to buy a lot of beacons at launch. Which means we would like to create a mobile app to act as a beacon, but not possible on Android on a lot of devices. Furthermore, we don't care about micro-locations which means we are not going to use beacons at 100% of their potential.
  • GPS: Not really good on a security aspect to assure to both devices that the location is the good one.
  • Manual check-in at location: The best way to be sure that device 2 went on the location of device 1 would be to do a manual check at location. But this is kinda frustrating because not innovative at all.

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.

Vere answered 14/3, 2017 at 22:32 Comment(9)
Have you tried using the Google Maps API? link I have personally used it previously to do something similar (also using Firebase to store the device's coordinates).Hollander
No I didn't, but I already thought about that solution. The problem is that I supposed it's based on the GPS coordinates of the users ? Which means it can easily be hacked with a faker ? linkVere
Well, there certainly is some security concerns... Unfortunately I cannot help you with that (although the question you linked to should be a good reference for such).Hollander
Indeed, users can use mock locations. And in our concept, if users claims to be at specific location but they aren't, our whole platform security can be concerned. That's why I was more looking for a way to measure distance between two devices with a way of communication avoiding incompatibilities between devices. On the other hand, a solution could be to use the library you gave me coupled with maybe a way of communication via bluetooth at location ? But we can't be sure the user is exactly at location, and I'm not sure it's doable via Ionic (Android -> Android, Android -> iOS etc ...).Vere
Just found out this library : thaliproject.org might be a solution ?Vere
If you use both libraries you might be able to acquire the user's supposed location and then check to see if it makes sense. Although exactly how you would go about that is beyond me (haven't tried that type of thing yet).Hollander
I'm trying since yesterday night to be able to instal everything and test their demo app which is : video. I could be able to make two apps communicating eachothers. Maybe I can even get a range between thoose devices who knows. Cordoga plugin so easy to integrate with Ionic I guess. Their is also an authentication between apps which is showed in the video. I'll try to test the app and see how it works and I'll try to keep the subject up to date to make at least a feedback.Vere
After few days of rearches I got two different answers : p2pkit : paying solutions, but also nearby : Google nearby which is free, but no integration with Cordova / Ionic.Vere
@Vere have you found a solution for this yet - to measure distance between iOS devices and android devices and/or iOS devices and iOS devices and/or android devices and android devices? Are there any solutions like p2pkit that are free for example?Verrocchio
G
0

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.

Gelya answered 23/3, 2017 at 10:8 Comment(2)
I already went into that direction, the problem is like I said, it's possible to listen for a BLE signal with this plugin, but actually impossible to emit as BLE on most of the phones. It's possible only on iOS and some of Android devices. The problem is that new phones support the BLE to scan, but not to emit. So in my case, this is kinda a dead-end for the moment. But BLE technology is good indeed to have distance.Vere
Now BLE does work between Android and iOS. And while many Android phones can't be a peripheral, most of them can be a central. So that's a problem in my case.Vere
M
0

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.

Marchall answered 22/4, 2019 at 14:30 Comment(1)
Won't work, because even if the devices are sitting right next to each other, the IP packets might be routed halfway around the world. For example, one device might be on one cellular carrier and the other device on another.Evaevacuant

© 2022 - 2024 — McMap. All rights reserved.