How to improve Geofencing reliability? - android

In my Android app I use geofencing features of Google Play Services.
For example a user drives a car (so his device has GPS signal), then the user stops and adds geofence for current location (with 300m radius), enters a building (the device loses GPS and guesses location using the cell network), then the user drives to next location. The app should calculate how much time the user spent in the building. I noticed that geofence exit events are quite unreliable in such scenarios. Very often there are no geofence exit events at all.
I wonder how to improve reliability of exit events. For example additionality to geofencing, the app can use activity recognition. When a user starts driving a car then the app can turn GPS on for a 15 seconds. So geofencing gets more accurate location data, thus so it can produce more accurate exit events.
Is this idea is reasonable? Maybe Google Play Services already does tricks like that.

Related

will geofence reduce power consumption vs just checking location every x seconds?

i'm creating a location tracking app to let users plot a heat map of where they traveled throughout the day. this involves constantly gps querying the user's location, a battery-intensive operation. one way i thought to reduce the app's power consumption is to set up a geofence after a few location updates return roughly the same value, and shutting down the location updates until the user exits the geofence (signifying that they are once again on the move).
this will allow my app to only perform frequent GPS queries when the user is actually moving (triggered by them exiting a geofence).
however, i'm not quite sure if this will reduce power consumption, because if the geofence is triggered by constantly querying the user's location to see if they have moved outside the fence, it will have basically the same effect on the battery.
so my question is, how does the geofence know when the user has left/entered the area? is it based on simple periodic location queries? or is there some more clever mechanism involved? thanks!
link to current version of app:
https://play.google.com/store/apps/details?id=com.russ.locationalarm&hl=en
The way Android is handling geofencing is quite complex. There are many differences between devices, but also between Android versions. But as a quick answer, your solution could save battery, because detecting a zone exit don't necessarily require GPS, but could use other location methods like Cell ID or Wifi, which are much less battery consuming. You also need to know that geofencing is not a 100% reliability solution, in particularly on Zone Exit events (less than 50% of zone exits detected in average), that are less reliable than Zone Enter events. Some companies like Herow, Radar, Foursquare are building SDKs that manage specifically geofencing.

Geofencing, iBeacons, and sending notifications when people walk into a restaurant

I'm trying to send a notification through my iOS and Android apps when a user walks through the front door of a restaurant. I've tried Geofencing, but the minimum radius isn't small enough and people will get notifications from multiple restaurants in the area. I know iBeacons exist. Are they my only option? (I know Foursquare sends these kinds of notifications, but I don't think they use iBeacons.)
Beacons are much more accurate than Geofences, but they still have a range of about 40 meters. In a dense urban area, beacons might still trigger notifications from multiple adjacent restaurants at the same time. You might also trigger the notification as the user walks by on the sidewalk. There are ways you can lesson the likelihood of this by placing beacons inside the restaurant so the signal is very weak outside. But you cannot eliminate it.
The Foursquare does use beacons. I know this because the Android version of their started being bundled with the Android Beacon Library about two years ago, and I'm the lead developer on that open source project. That said, I suspect they use a combination of geofences and beacons, only using beacons for cases where customers actually have them installed.
Geofence-based notifications are especially problematic on iOS because geofences often fall back to location from cell towers to save battery when no location apps are in the foreground. Cell tower locations are only accurate within a kilometer or two, and will trip a geofence of the outer range of the location uncertainty overlaps with the geofence. This can trigger a restaurant welcome notification from over a mile away.
One way to improve bad Geofence-based notifications like this is to use the following technique on iOS:
Request an extra 180 seconds of background running time when the geofence is tripped.
Request location updates with GPS, and monitor these updates for 180 seconds in the background.
Using the location update data, if you find that the accuracy of the fix is high enough and the distance from the restaurant is small enough, then trigger the notification. Until and unless this happens, don't trigger it at all.
You would need a beacon inside the restaurant already, otherwise geofencing is going to be your only option. You could combine geofencing with a gps call and see if the gps call is within a lat long you have deemed to be inside that establishment, and then repeat this gps call every few minutes while you are inside the geofence until it matches a coordinate inside the place.
The disadvantage to this approach is that the battery drain will be higher than using ibeacons, which operate using BLE (bluetooth low energy)

Use Google Fused Location API in background to track distance

For a school project, i have to do an Android project (i am new to Android coding) where i must track the user location and record his travelled distance.
For this, i use the Google Fused Location API.
I am having good results concerning the tracking, but it is only working when the app is in the foreground.
I have to continue to track the user location even when the phone is sleeping, and calculate his travelled distance.
I made some researches and found some solutions with AlarmManager, or with the requestLocationUpdates using PendingIntent. But i can't figure out what is the best to use in my situation.
The "only" thing i want to do while the phone is sleeping is to continue getting his location and increment a float with his distance, so i can update the UI when the user is back on the app screen with his correct distance travelled.
What is the best way to do this in my case ?
Thank for your answers.

Does coarse location use less battery than geofences on Android?

I'm trying to know when your device leaves your home, but I don't need fine GPS location nor high update rate (i.e. it's fine if I know the user is out only 10 minutes after he left his home and he's already 100 meters away).
Which of the two solutions should use less battery (both should use already less battery than plain GPS location listener)?
Receiving Location Updates | Android Developers with PRIORITY_BALANCED_POWER_ACCURACY
Creating and Monitoring Geofences | Android Developers
The first is for sure using a more battery saving solution and I can control the frequency to be low.
The second is a higher level API which does just what I want but I've no idea what it does and it looks like it'll use fine GPS location constantly while the user is within the geofence (remember I want to reduce battery usage).
Anyone has some insight on this regarding mostly battery usage?
The answer here might be a combination of things. The Location and battery Drain video explains more about how the GPS & Location chips burn up battery in your device. (Battery Drain and Networking will detail how the Radio chips work.)
Basically, using a FusedLocationProvider will allow you to scale back accuracy vs. power drain. Basically less-resolution results in less battery drain.
Knowing that, I'd suggest a set of low-power checks as early-warnings before moving to the higher-power checks:
Use ConnectivityManager to determine if the mobile device is on the CellularNetwork or not. If they are, there's a good chance they've moved outside of the wifi boundries.
Check if the WiFi they are connected to is the common home WiFi (so you don't mistake the coffeeshop wifi as home).
Use a back-off system on your checks. If the user is home, chances are, they will be there for a while; so scale back how often you check position.
If the user is on Cell network, use a Course Location to determine if you're within 100ft of your known home location.
Use a Fine location check to resolve issues / corner cases with the Course Location check.
When all else fails, do a Geo Fencing check; but then turn it off as soon as you've resolved the issues.
Basically, you want the least-power draining options to run the most often, and only use the most power-draining when you're resolving discrepancies in position.
There are a few hints in the documentation that Google wants you to use the Geofencing (or the new Awareness API) for your use case.
The first method need to be triggered from a LocationRequest, and from
https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest
Activities should strongly consider removing all location request when entering the background (for example at onPause()), or at least swap the request to a larger interval and lower quality.
This shows that this API is designed to be used only when your application is active, hence the "Request" term.
Google soon realized that a lot of apps (including their own Google Now) are requesting for location in the background, and they want to improve it in such a way that the requests can be pooled and shared, hence they created Geofencing and eventually Awareness API.
From the Fence API document,
https://developers.google.com/awareness/overview#fences_and_snapshots
Fence API lets your app react to the user's current situation, and provides notification when a combination of context conditions are met. For example, "tell me whenever the user is walking and their headphones are plugged in". Once a fence is registered, the Fence API can send callbacks to your app even when it's not running.
So, in your use case, if your app is not running, you should be using the second method.

Android Geofence api versus active polling with a plugged in device

If power is not an issue, what is the best method to track geofence events on an android device (specifically a Nexus 7). Geofence api, or active polling
The tablet is permanently fixed in a vehicle and always powered. So power saving is not a concern.
Is there any downsides to using the Geofence api? It seems to be designed to conserve power. Perhaps it is not as accurate? Would our app be more responsive to a geofence crossing if we were actively polling instead?
The position data available to the device is cell tower and GPS. No wifi.
Google Play Services Geofence API is as accurate as current known location. If battery power isn't an issue, then you can use a service in your app to keep GPS on for the whole time. In this way you don't have to implement your code which will detect enter, exit, dwell events.
However the Geofence API is limited to 100 geofences per app. If the limit is an issue then probably it is easier to not use Google Play Services and implement your code to detect geofences events. The code should be trivial having accurate GPS location all the time.
The main problem Google Play Services Geofence implementation tries to solve is battery usage.

Categories

Resources