Reputation: 255
I've searched online but haven't yet found anything like this. Basically, is there a way where I can know if I'm facing a certain location.
For example, I have my current location in latitude & longitude and I have a second location in latitude & longitude. Now I want to know when the second location is directly in front of me as I turn.
Upvotes: 2
Views: 1106
Reputation: 2234
I'm going to assume that you mean the phone is "facing" the location of interest, and you already know which axis will determine this. What I would do is use the SensorManager.getOrientation(float\[\], float\[\])
to get the radians of where you device is facing, then convert it into degrees.
Next, I would ensure I get an accurate and current point from the device (GPS, not Network), and call Location.bearingTo(Location)
on the location from the device with the destination location as the parameter to get the degrees to it.
Finally, I would compare the two results and determine if the device is "facing", within a certain range. This might have to be adjusted based on how far the destination is from the current location, but I would experiment with this a bit.
Upvotes: 4
Reputation: 118
I don't know if this help, but you could take a look at the Places API from Google: https://developers.google.com/maps/documentation/javascript/places#place_search_responses
The response has an attribute called viewport that with some processing can help you
Upvotes: 0
Reputation: 153
You can predict your direction/location if you use Android location Manager. Take a look at this example
Upvotes: 0