# Android Question[Solved] - BearingTo from GNSS returns negative results for locations West of my location.

#### rleiman

##### Well-Known Member
Greeting Everyone,

I'm trying to use BearingTo from GNSS, but it returns negative results for locations West of my current location. These results also include locations such as Northwest and Southwest of my location. I'm probably not using BearingTo correctly. In that case, I was expecting it to return a number somewhere between 0 and 359. For locations East of my current location, I get accurate results. Can you let me know what I still need to do to get the correct results for the westerly locations?

Here's the coordinates for several locations I used to test BearingTo:

B4X:
``````BearingTarget.Initialize2("42.537289", "-71.512802") ' Littleton, MA from Westford, MA
BearingTarget.Initialize2("42.599814", "-71.367284") ' Chelmsford, MA from Westford, MA
BearingTarget.Initialize2("42.765366", "-71.467566") ' Nashua, NH from Westford, MA
BearingTarget.Initialize2("42.764811", "-71.439788") ' Hudson, NH from Westford, MA``````

Littleton is Soutwest of me.
Chelmsford is Eastnortheast of me.
Nashua is Northnorthwest of me.
Hudson is Northnortheast of me.

Here are the numbers returned by using this statement:
B4X:
``intMyHeading = NumberFormat( Location1.BearingTo( BearingTarget ), 3, 0)``

Littleton: -121
Chelmsford: 60
Nashua: -3
Hudson: 3

If I use Littleton as an example, I was expecting BearingTo to return a number somewhere between 220 and 250. As a quick fix you can tell me what number to add to the returned negative number to use an accurate bearing to?

I included a map so you can see the relation of the locations compared to Westford.

Thanks.

#### agraham

##### Expert
Littleton = -121 = 360-121 = 240

Conventionally longitudes West of the meridian are -ve values 0 to 180, East is +ve values 0 to 180. I guess this is reflected into the bearing values.

#### rleiman

##### Well-Known Member
Littleton = -121 = 360-121 = 240

Conventionally longitudes West of the meridian are -ve values 0 to 180, East is +ve values 0 to 180. I guess this is reflected into the bearing values.
Thanks for such a quick reply and very helpful solution which I will now incorporate into the app.

#### rleiman

##### Well-Known Member
bearing = IIF(bearing < 0, 360-bearing, bearing)
Thanks so much for that super helpful coding! I forget they recently included the double "IF" into the language.

Replies
40
Views
2K
Android Question GPS BearingTo
Replies
1
Views
951
Replies
50
Views
25K