问题
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!
回答1:
I'd use getLastLocation and then getBearing but I'd not expect great accuracy.
回答2:
You better off using GPS, since for sensor the phone has to be in specific position, that is the screen has to face the opposite direction of driving. For GPS, the position of the phone does not matter.
来源:https://stackoverflow.com/questions/29737344/get-the-direction-android-app-user-is-headed-on-entering-a-geofence