title: Not able to get Location by GPS : Android
body: <p>I am new to android. I am trying to get my location using GPS.
  I have included the permissions:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt;
  &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
  </code></pre>
  
  <p>Whenever I am trying to get my <code>Location</code> from <code>LocationManager</code> using <code>getLastKnownLocation</code> I am getting null object. Also, GPS is enabled. Here is my code:</p>
  
  <pre><code>LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
  Location location;
  if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
      Log.d("ManualLog", "GPS_DISABLED");
      Intent settingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      startActivity(settingsIntent);
  } else {
      Log.d("ManualLog", "GPS_ENABLED");
      location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
  }
  </code></pre>