I have done this code where I want to get longitude and latitude , but using both network provider and gps provider i get my location null . even if gps is enabled ... why so?
boolean isGPSEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); boolean isNetworkEnabled = lm .isProviderEnabled(LocationManager.NETWORK_PROVIDER); Location location = null; if (!isGPSEnabled && !isNetworkEnabled) { } else if(isGPSEnabled ) { location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); if(location == null) { if(isNetworkEnabled) location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if(location == null) { } } } else if(isNetworkEnabled){ location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if(location == null) { } }