Search code examples
androidandroid-sensorsandroid-locationandroid-geofence

Get the direction Android app user is headed on entering a geofence


I'm playing around with geofences - what I'd like to do is when a geofence is fired, figure out which direction they're going.

For example - let's ay I want to setup a geofence around a Culvers. While driving down the interstate heading north, when I enter the geofence I want to pop-up a notification that says "Culvers, take next exit on the right and make a right heading East".

But if they're driving South on the interstate, it should pop-up and say "Culvers, take next exit on the right and make a left heading East".

Not the best example, but hopefully that gets the idea across.

A few thoughts I had: 1. Make a few GPS or fused location requests and use those to determine where the user is headed. 2. Use the sensor to determine what direction the phone is facing. - I've never used these APIs though so I'm not really familiar if it's easy to get that info.

Thoughts on those ideas? Better recommendations?

Thanks!


Solution

  • I'd use getLastLocation and then getBearing but I'd not expect great accuracy.