Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>pleas check your manifest file.whether have you added those permissions or not.</p> <pre><code> &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"&gt;&lt;/uses-permission&gt; &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"&gt;&lt;/uses-permission&gt; </code></pre> <p>See the updated answer:</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, myLocationListener ); timer = new Timer(); timer.schedule(new GetLastLocation(),20000); } class GetLastLocation extends TimerTask { @Override public void run() { timer.cancel(); locationManager.removeUpdates(locationListener); 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(); } } return; } } /** The location listener. */ LocationListener myLocationListener = 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) {} }; </code></pre>
 

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