Note that there are some explanatory texts on larger screens.

plurals
  1. POcurrent location is always null
    primarykey
    data
    text
    <p>I am trying to retrieve my current location on the button click in an editbox using gps or network..i have tried all possible methods which i found in tutorials and older posts....but my location is always null.. i am not getting where i am wrong.? i am testing it on real device having network but no internet/gprs...</p> <p>this is the code which i am using..i tried the same with GPS_PROVIDER as well ..please help me..</p> <pre><code> protected void showCurrentLocation() { geocoder = new Geocoder(this); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, MINIMUM_TIME_BETWEEN_UPDATES, MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, new MyLocationListener() ); Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); System.out.println("loc.."+location); if (location != null) { String message = String.format("Location \n Longitude: %1$s \n Latitude: %2$s", location.getLongitude(), location.getLatitude()); Toast.makeText(ShowActivity.this, message, Toast.LENGTH_LONG).show(); //acTextView.setText(message); try { List&lt;Address&gt; addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 10); //&lt;10&gt; for (Address address : addresses) { System.out.println("my location .."+address.getAddressLine(0)); acTextView.setText(address.getAddressLine(0)); } } catch (IOException e) { Log.e("LocateMe", "Could not get Geocoder data", e); } } else { AlertDialog.Builder alertbox1 = new AlertDialog.Builder(this); alertbox1.setMessage("No GPS or network ..Signal please fill the location manually!"); alertbox1.setNeutralButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) {}}); alertbox1.show(); } } </code></pre> <p>I am just editing the question instead of asking the new one..because my problem is still related to the same...i didn't change anything in the code and this is working perfectly fine now.....But the issue is when i use the GPS_PROVIDER ,it returns the accurate address along with the value of longitude and latitude..but when i use NETWORK_PROVIDER it returns only the value of longitude and latitude no address...i want to retrieve the full address using NETWORK_PROVIDER because GPS not works indoor ...How can i do that?</p> <p>Thanks...!!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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