Improving Google’s Geofencing
Lately I’ve decided to try out the new Location APIs included in Google’s Play Services. Specifically, I wanted to see how the new Geofencing feature looks like and what can I do with it.
Since necessity is the mother of invention, it seemed appropriate to try it on my home’s parking gate. My gate has a modem connected to it, and in order to open it you have to call a certain phone number. The modem recognizes the caller ID, verifies that the caller is authorized to open the gate, and if so – it just opens it (without answering the call, of course).
A-HA! So why not define a geofence around the gate, and let my phone call it automatically as soon as I arrive?
So I set up and wrote an app (actually, a service) which does exactly that. But when I tested it, I encountered a problem – the fence’s trigger arrived quite late. Almost every time I got at the gate, it took some time till the fence recognized I’m actually there and opened it. I was left hanging out to dry, till the Location service would kindly decide to refresh its data.
So I needed a way to force the Location APIs to use the GPS more frequently when I’m near the fence.
Ok, so let’s force it! I defined a second geofence, with a bigger radius than the first one. Upon getting a trigger for the new outer geofence, I registered my service to receive location updates. Whenever I got such an update – I actually did nothing with it! However, the side effect was that the original geofence enjoyed a frequent refresh in GPS data, resulting in a much more accurate location.
Thinking of this solution, I realized that when registering a goefence, I expect the API to also get an “accuracy” parameter from the app. Then, the Location service can decide by itself when to use the GPS – for example, by using the activity recognition mechanism: if I’m walking, it would start the GPS only when I get within 1000ft from the fence, and if I’m driving, it would start it at a much farther distance.
- When entering the inner geofence – I immediately stop the location updates.
- Also, if the user has entered the outer geofence, after X minutes without entering the inner one, I stop the updates. I don’t want to drain the battery.
- In my experience, after getting home, I’ve noticed that from time to time the device thinks it exited the inner geofence, and then back in it. So – if the user exited the inner one, but didn’t exited the second one after that, I will not open the gate if he is back in the inner one.
4 Responses to “Improving Google’s Geofencing”
Leave a Reply
- Here at KwazyLABS, we love the Qualcomm’s...
- Background Lately I’ve decided to try out...
- PromaxBDA Global Excellence 2013 Announce...
- A stylish multi-player crowd game for smartphon...
- KwazyLABS and Yes DBS Satellite Win the MOBI Aw...