javaandroidlatitude-longitudecompass-geolocation

How to konw the Primary InterCardinal direction (N,E,S,W) of a place using the current location latitude and longitude?


I'm kind of lost here, I'm working on my app and this really confused me. Let me explain it like this, for example;

A- is my current location with Lat&Long. B- is another location Lat&Long.

Now, I want the lat&Long of B pointing toward A Lat&Long. However, I want to get the data as Compass Degree and Primary InterCardinal directions

Something like this: <== Just an Example not real :)

A- Current Location: Washington, D.C. ,USA B- Another Location: Ottawa, Canada

The output something like:- B to A: 185 Degree, South West (SW)

Thanks in Advance

P.S. I Already Created a Compass Activity, and I know how to get my current location as will getting the other location lat&long.


Solution

  • Use Location.bearingTo to get the angle between the two locations. The return is degrees, with 0 being north and going clockwise from there. You can do the math yourself to figure out a bearing. Just divide those 360 degrees into equally sized ranges with the exact bearing you want to print in the center of each range, and see which range its in.