0

Background:

I am developing a navigation app for android using mapquest maps. I have wearble device which vibrates when the user has to turn left/right. Now, as the user deviates from the path computed by mapquest, a rerouting occurs. The newly created path sometimes, is different from user heading. So, I would like to indicate the user to turn left/right/back to get back on the new path and the regular navigation process continues there on.

problem:

How to calculate the bearing between stationary user heading and a geopint, such that I could put that geopint in N/S/E/W quadrants in reference to the user location and indicate to turn left if it is west or right if it is East

Here is a link to a picture which dscribes the concept metioned above

https://www.dropbox.com/s/m8tugeavmjb46ck/Untitled.jpg?dl=0

Please help me out here

thanks

goku2512
  • 73
  • 1
  • 4

1 Answers1

1

You need to calculate the angular difference between the direction in which the user is facing / heading and the vector connecting the user's location to the destination geopoint. In the picture that you shared, this angle will be 90 degrees anticlockwise.

Calculation of facing / bearing direction: If the user is moving, use location.getBearing(). If stationary, use the compass to get the facing direction.

Calculation of direction of vector from current location to the destination: use myLocation.bearingTo(destination)

Finally, compute the difference between the 2 directions

Price
  • 2,683
  • 3
  • 17
  • 43
  • When the user is facing the destination point, the difference in direction is around 30 degress. Isn't it supposed to be around 0 degrees. The code im using follows. Location loc = new Location("current"); loc.setLatitude(im.getCurrentInstruction().getDecisionPoint().getLatitude()); loc.setLongitude(im.getCurrentInstruction().getDecisionPoint().getLongitude()); float dir1= location.getBearing(); float dir2=location.bearingTo(loc); float resValue=dir1-dir2; – goku2512 Jan 14 '15 at 16:32
  • Like I said in my answer, if you are stationary, the bearing does not give the direction in which you are facing. Use compass direction to get your orientation. – Price Jan 15 '15 at 14:20
  • Hi again, I used location.getbearing() and I wasn't stationary. It gave some weird values like 0,180,280 while moving along a straight line towards the destination point. And location.bearingto gave values around 30. So the difference doesn't make any sense – goku2512 Jan 15 '15 at 15:33
  • The bearing is 0 if you are stationary. When moving along a straight line, I can tell from experience that it will give you a constant and correct angle in degrees clockwise from North. – Price Jan 15 '15 at 17:43
  • @goku2512 the bearingTo gives angle from true north (180 to -180) you need to convert it to normal angle from target using methods described here - http://stackoverflow.com/questions/4308262/calculate-compass-bearing-heading-to-location-in-android – Gabriel H Mar 04 '15 at 11:15