Note that there are some explanatory texts on larger screens.

plurals
  1. POgetLastKnownLocation() return always null on device
    text
    copied!<p>In the code below <code>getLastKnownLocation()</code> always returns null on a device, even when I am getting <code>Provide = internet</code>. It was working fine but know it's returning a null value. I am using a Galaxy Tab version 2.2.</p> <pre><code>public void find_Location(Context con) { Log.d("Find Location", "in find_location"); this.con=con; String location_context = Context.LOCATION_SERVICE; LocationManager locationManager = (LocationManager)con.getSystemService(location_context); List&lt;String&gt; providers = locationManager.getProviders(true); for (String provider : providers) { locationManager.requestLocationUpdates(provider, 1000, 0,new LocationListener() { public void onLocationChanged(Location location) {} public void onProviderDisabled(String provider){} public void onProviderEnabled(String provider){} public void onStatusChanged(String provider, int status,Bundle extras){} }); Location location = locationManager.getLastKnownLocation(provider); if (location != null) { lat = location.getLatitude(); lng = location.getLongitude(); Geocoder geocoder = new Geocoder(AdvanceSearch.this, Locale.getDefault());List&lt;Address&gt; addresses; try { addresses = geocoder.getFromLocation(lat,lng,100); countryname=addresses.get(0).getCountryName(); eexit e = new eexit(); statename= addresses.get(0).getAdminArea(); cityname=addresses.get(0).getLocality(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } </code></pre> <p>Thanks in advance for your help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload