Detect whether moving away from particular marker or towards in Android?
I am developing an application where I want to know whether I am moving towards a particular location or away from it. I know the latitude and longitude of that particular location. For eg, say I am at x location and moving towards y which is say 100 miles away. Now, if I calculate the distance between this two locations then its always positive so I d开发者_StackOverflow中文版o not know whether I am moving away or towards. The second option would be keep track of previous distance and compare the previous one and new one and see if its larger then I am moving away may be.
In Android we do get the heading from GPS. Then is there some way that I can use that information to track whether I am moving towards y or away from it.
You should be able to get a general idea by calculating a bearing between your current location and the destination, and then comparing that to your current heading. See calculating distance and bearing for the math.
精彩评论