title: Android Location getBearing() always returns 0
body: <p>I've been trying to implement a feature for my Android app that gets the speed and direction of travel of the device, no matter where the device is pointed at. For example: If my Android device is pointed in the North direction and if I'm moving backwards in the South direction, it would return that I'm moving Southbound. </p>
  
  <p>I've been looking around and I have came up with a possibility of using the Location's getBearing() method (Still, I do not know if that will solve my whole problem). When I invoke getBearing(), it always returns 0.0 for some reason. I have no idea why. Here is my code:</p>
  
  <pre><code>LocationManager lm;
  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_gcm);
      setUpUI(findViewById(R.id.LinearLayout1));
      isRegged = false;
  
      // GCM startup
      gcm = GoogleCloudMessaging.getInstance(this);
      context = getApplicationContext();
  
      gps = new GPSTracker(context);
      // gps.startListening(context);
      // gps.setGpsCall(this);
  
      /*
       * Variables to indicate location and device ID
       */
      TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
  
      if (gps.getIsGPSTrackingEnabled())
      {
          longitude = Double.valueOf(gps.getLongitude()).toString();
          latitude = Double.valueOf(gps.getLatitude()).toString();
      }
  
      deviceID = telephonyManager.getDeviceId();
  
      mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
  
      lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
      lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, (float) 0.0,
              this);
  }
  </code></pre>
  
  <p>This is where I am getting the bearing.</p>
  
  <pre><code>@Override
  public void onLocationChanged(Location currentLocation)
  {
      float speed = 0;
      float speed_mph = 0;
  
      if (previousLocation != null)
      {
          float distance = currentLocation.distanceTo(previousLocation);
  
          // time taken (in seconds)
          float timeTaken = ((currentLocation.getTime() - previousLocation
                  .getTime()) / 1000);
  
          // calculate speed
          if (timeTaken &gt; 0)
          {
              speed = getAverageSpeed(distance, timeTaken);
              speed_mph = (float) (getAverageSpeed(distance, timeTaken) / 1.6);
          }
  
          if (speed &gt;= 0)
          {
              info_text.setVisibility(View.VISIBLE);
              info_text_mph.setVisibility(View.VISIBLE);
  
              DecimalFormat df = new DecimalFormat("#.#");
              info_text.setText("Speed: " + df.format(speed) + " " + "km/h");
              info_text_mph.setText("  Speed: " + df.format(speed_mph) + " "
                      + "mph");
  
              if (speed &gt;= 10 &amp;&amp; lm.getProvider(LocationManager.GPS_PROVIDER).supportsBearing())
              {
                  float degree = currentLocation.getBearing();
  
                  direction_text.setVisibility(View.VISIBLE);
  
                  Log.i(TAG, String.valueOf(degree));
  
                  if (degree == 0 &amp;&amp; degree &lt; 45 || degree &gt;= 315
                          &amp;&amp; degree == 360)
                  {
                      direction_text.setText("You are: Northbound");
                  }
  
                  if (degree &gt;= 45 &amp;&amp; degree &lt; 90)
                  {
                      direction_text.setText("You are: NorthEastbound");
                  }
  
                  if (degree &gt;= 90 &amp;&amp; degree &lt; 135)
                  {
                      direction_text.setText("You are: Eastbound");
                  }
  
                  if (degree &gt;= 135 &amp;&amp; degree &lt; 180)
                  {
                      direction_text.setText("You are: SouthEastbound");
                  }
  
                  if (degree &gt;= 180 &amp;&amp; degree &lt; 225)
                  {
                      direction_text.setText("You are: SouthWestbound");
                  }
  
                  if (degree &gt;= 225 &amp;&amp; degree &lt; 270)
                  {
                      direction_text.setText("You are: Westbound");
                  }
  
                  if (degree &gt;= 270 &amp;&amp; degree &lt; 315)
                  {
                      direction_text.setText("You are: NorthWestbound");
                  }
  
              }
  
          }
      }
      previousLocation = currentLocation;
  
  }
  </code></pre>
  
  <p>Thanks so much!</p>