2
    lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    Criteria c = new Criteria();

    provider = lm.getBestProvider(c, false);
    l = lm.getLastKnownLocation(provider);
    if (l != null) {


        longitude = l.getLongitude();
        latitude = l.getLatitude();
    }

I have code to get longitude and latitude of user's location. It works fine in certain android devices only when it returns provider by network. However, when it returns provider by gps in some other devices, it does not return user's location. It returns null Please help me

Farruh Habibullaev
  • 2,342
  • 1
  • 26
  • 33
  • You meant this ? http://stackoverflow.com/questions/23906926/locationmanager-getlastknownlocation-return-null –  Jul 22 '15 at 10:47
  • No its different. I have this method. It find the best provider. and returns location's longitude and latitude accordingly.But when provider returns gps, lastKnownLocation returns null – Farruh Habibullaev Jul 22 '15 at 11:11
  • Besides, when i debug application on my phone Galaxy Note 2, it returns only provider gps, is that possible to return provider network on that phone? – Farruh Habibullaev Jul 22 '15 at 11:16
  • Yes, make a call to isProviderEnabled(NETWORK_PROVIDER) and if true call requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this) and implement LocationListener. See this Tutorial: http://developer.android.com/guide/topics/location/strategies.html#Updates –  Jul 22 '15 at 11:41

0 Answers0