Psngr app is quite smart when it comes to tracking mileage and detecting trips, travel modes and places you visit. We've written the app to rely on no external hardware and detect a new trip automatically when you start moving. To achieve this without constantly hogging the GPS and draining your device's battery, we use geofencing.
Geofencing is power-efficient because it only approximates your location. It relies on cellular tower triangualtion and WiFi hotspots instead of GPS (satellite) signal. As such, it is far less accurate than GPS and may detect movement only if you move a couple of hundreds of meters or more. This level of accuracy varies depending on the amount of WiFi hotspots and cellular antennas around you.
Psngr app uses geofencing by adding a geofence circular region around your current location. When you exit this region, the operating system (iOS or Android) launches the app and delivers the event that you've exited the geofence region. In code, it looks like this:
CLCircularRegion(center: location.coordinate, radius: radius, identifier: identifier)
The limitations of geofencing
Sounds pretty straightforward and simple, right? Unfortunately, this doesn't work all the time. In fact, we have found two problems with this approach:
- Geofencing can be unreliable sometimes in terms of getting the notification when a user exits a geofence region.
- When the app does receive the exit event and starts recording the trip, it cannot determine which vehicle is being used, and therefore defaults to the last vehicle used. Since you may be using multiple modes of transport and/or vehicles (multiple cars, public transport or even bicycle), this can add an extra step wherein you would have to manually edit the vehicle used if it was not assumed correctly.
So to sum up, we needed a solution which would give us reliable trigger to start logging a new trip automatically, as well as detect which vehicle is to be used.
Enter beacons. #drumroll
A beacon is a small Bluetooth radio transmitter which transmits a signal that other devices can see. The way we've incorporated beacons into Psngr is simple:
- Get a beacon device (you can order one within Psngr app v3.3 or later)
- Plug the beacon in your car's USB port and start the engine
- Psngr app will immediately detect the beacon and ask you to assign it to a specific vehicle within the app.
- From now on, the beacon stays in your car!
- One beacon per car. If you have more than one car, connect a separate beacon to each car.
When you assign a beacon to a specific vehicle within Psngr app, the app starts monitoring that beacon. This works in a similar way to location-based geofencing, only the geofencing is associated with a beacon device, not a particular location. Instead of adding a
CLCircularRegion, we add a
CLBeaconRegion as follows:
CLBeaconRegion(proximityUUID: proximityUUID, identifier: identifier)
Whenever you enter your car and start the engine, the beacon will start transmitting its signal and Psngr app will detect that beacon and start logging your trip. At the same time, your vehicle, identified by the specific beacon ID, will be associated with the new trip.
Similarly, when you turn off the engine, Psngr will detect that the beacon signal stopped and will end the trip.
Try it out!
For the developers amongst you, we've provided Trckr framework, an open iOS framework for location tracking that supports beacons, too.