User location cannot be found
<p>I post a question not long ago. Basically what I am trying to do is have my location manager return my longitude and latitude. My getBestProvider() method returns network, however my locationManager.getLastKnownLocation(provider) returns null. As you can see I've implemented the listener. I must have done something wrong.</p>

<p>Here is the code.</p>

<pre><code>public class Activity1 extends Activity implements LocationListener {
       private LocationManager locationManager;
       private String provider;



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    readFile();




            locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

            Criteria criteria = new Criteria();
            provider = locationManager.getBestProvider(criteria, false);
            System.out.println(provider);
            System.out.println(locationManager.getProviders(criteria, false));
            System.out.println(locationManager.getProvider("network"));
            System.out.println(locationManager.getAllProviders());


            Location location = locationManager.getLastKnownLocation(provider);

            // Initialize the location fields
            if (location != null) {
                System.out.println("Provider " + provider + " has been selected.");
                int lat = (int) (location.getLatitude());
                int lng = (int) (location.getLongitude());
                System.out.println(String.valueOf(lat));
                System.out.println(String.valueOf(lng));

            } else {
                System.out.println("Provider not available");
                System.out.println("Provider not available");
            }


}@Override
protected void onResume() {
    super.onResume();
    locationManager.requestLocationUpdates(provider, 400, 1, this);
}

/* Remove the locationlistener updates when Activity is paused */
@Override
protected void onPause() {
    super.onPause();
    locationManager.removeUpdates(this);
}

@Override
public void onLocationChanged(Location location) {
    int lat = (int) (location.getLatitude());
    int lng = (int) (location.getLongitude());
    System.out.println(String.valueOf(lat));
    System.out.println(String.valueOf(lng));
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    // TODO Auto-generated method stub

}

@Override
public void onProviderEnabled(String provider) {
    Toast.makeText(this, "Enabled new provider " + provider,
            Toast.LENGTH_SHORT).show();

}

@Override
public void onProviderDisabled(String provider) {
    Toast.makeText(this, "Disenabled provider " + provider,
            Toast.LENGTH_SHORT).show();
}
</code></pre>

<p>}</p>
