title: GPS location provider gives me null location in Android
body: <p>I try to find location using <code>GPS_Provider</code> in android. when try to get location using <code>Network_Provider</code> than it give me location and call callback function properly, but when I tried to get location using <code>GPS_Provider</code> than it give me location <strong>null</strong> &amp; also not calling callback function <code>onLocationChanged</code> of <code>LocationListener</code>.</p>
  
  <p><strong>My code is:</strong></p>
  
  <pre><code> LocationManager lm;
      boolean isNetwork = false;
      Location location;
      LocationListener locationListener;
      LocationListener loc;
      MyLocation myLocation;
      Location location1;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
  
          try {
              myLocation = new MyLocation();
  
              if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &amp;&amp; ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                  // TODO: Consider calling
                  Log.e("Location", "Permission Not Given");
                  return;
              }
              Log.e("Location", "Permission is Given");
              lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, myLocation);
              location1=lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
          }catch(Exception e)
          {
  
          }
      }
  </code></pre>
  
  <p><strong>MyLocation.class</strong></p>
  
  <pre><code>public class MyLocation implements LocationListener {
      @Override
      public void onLocationChanged(Location location) {
  
          if(location!=null)
          {
  
              String lat,Longi;
              lat=String.valueOf(location.getLatitude());
              Longi=String.valueOf(location.getLongitude());
  
              Log.e("Latitude: " , lat);
              Log.e("Longitude: " , Longi);
  
          }
          else
              Log.e("Location is null", "Location not Found");
      }
  
      @Override
      public void onStatusChanged(String provider, int status, Bundle extras) {
          Log.e("Latitude: " ,""+ provider+ " Status: "+status);
      }
  
      @Override
      public void onProviderEnabled(String provider) {
  
      }
  
      @Override
      public void onProviderDisabled(String provider) {
          Log.e("Latitude: " , provider);
      }
  }
  </code></pre>
  
  <p>It give me logcat error as follow:</p>
  
  <pre><code>02-04 00:50:52.280 14480-14480/com.arc.locationusingnetwork E/Location: Permission is Given
  02-04 00:50:52.360 14480-14480/com.arc.locationusingnetwork E/IMGSRV: :0: PVRDRMOpen: TP3, ret = 46
  02-04 00:50:52.370 14480-14480/com.arc.locationusingnetwork E/IMGSRV: :0: PVRDRMOpen: TP3, ret = 49
  02-04 00:50:52.370 14480-14480/com.arc.locationusingnetwork E/IMGSRV: :0: PVRDRMOpen: TP3, ret = 50
  02-04 00:50:52.380 14480-14480/com.arc.locationusingnetwork E/IMGSRV: :0: PVRDRMOpen: TP3, ret = 50
  02-04 00:50:52.380 14480-14480/com.arc.locationusingnetwork E/IMGSRV: :0: PVRDRMOpen: TP3, ret = 50
  02-04 00:50:52.390 14480-14480/com.arc.locationusingnetwork E/IMGSRV: :0: PVRDRMOpen: TP3, ret = 52
  </code></pre>