Note that there are some explanatory texts on larger screens.

plurals
  1. POI want to use GPS but my code uses WiFi..!!! why?
    text
    copied!<p>I have written the following code that returns my current location address. But i can get these values only if the my Wifi is switched on manually. but i want to switch on the Gps and get my address from GPS and not from Wifi. Someone please tell me what is to be modified in this code to do so. Following is the code am using to locate my current address. Thanks in advance. </p> <pre><code>public String myloc() { criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); String provider = locationManager.getBestProvider(criteria, true); // Update the GUI with the last known Location location = locationManager.getLastKnownLocation(provider); if(location!=null) { double lat = location.getLatitude(); double lng = location.getLongitude(); latLongString = "Lat:" + lat + "\nLong:" + lng; Geocoder gc = new Geocoder(this, Locale.getDefault()); try { List&lt;Address&gt; addresses = gc.getFromLocation(lat, lng, 1); StringBuilder sb = new StringBuilder(); if (addresses.size() &gt; 0) { Address address = addresses.get(0); sb.append(address.getAddressLine(0)).append("\n"); sb.append(address.getLocality()).append("\n"); sb.append(address.getAdminArea()).append("\n"); sb.append(address.getCountryName()); } addressString = sb.toString(); } catch (IOException e) { } } else { latLongString = "No location found"; } return addressString; } </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