Note that there are some explanatory texts on larger screens.

plurals
  1. PONot getting Lat and Long through either GPS or Network
    text
    copied!<p>I am trying to get location using <code>GPS provider</code> or <code>Network provider</code> but i didn't get location from either <strong>GPS</strong> or <strong>Network</strong>.<br> Here is my code which was working fine some days ago but now it's not working.<br> I don't understand where i am wrong because all permission are already added in <strong>AndroidManifest.xml</strong>.<br> Here is the code which helpful for you to understand.</p> <pre><code>public class SearchDishoom extends Header implements LocationListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.searchdish); manager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000000, 100, this); locationListenerNetwork = 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) {} }; if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { // if gps provider is not enable then popup alertbox buildAlertMessageNoGps(); } else { // if gps is one then start searching locationListenerGps = 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) {} }; manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000000,100, locationListenerGps); } } /* * Get location (lat-long) from sharedpreference to further use */ prefLocation = getSharedPreferences("myLocation", MODE_WORLD_READABLE); String userLocationLat1 = prefLocation.getString("Lat", String.valueOf(0)); String userLocationlong1 = prefLocation.getString("Long", String.valueOf(0)); String address = prefLocation.getString("Address", "Location not found not found"); userLocationLat = Double.parseDouble(userLocationLat1); userLocationlong = Double.parseDouble(userLocationlong1); // set lat-long value in getset class for use of another activity gs = new GetSet(); gs.setLatitude(userLocationLat); gs.setLangitude(userLocationlong); if (userLocationLat == 0 &amp;&amp; userLocationlong == 0 &amp;&amp; address.equals("")) { /* * if lat-long is 0 or null then start searching using * GPS Provider or Network Provider */ manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); manager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListenerNetwork); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { buildAlertMessageNoGps(); } else { manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000000,100, locationListenerGps); } } else { // set lat-long value in getset class for use of another activity gs.setLatitude(userLocationLat); gs.setLangitude(userLocationlong); setLocationName(userLocationLat, userLocationlong); } } </code></pre> <p>Here is override onLocationchanged(): </p> <pre><code>@Override public void onLocationChanged(Location location) { userLocationLat =location.getLatitude(); userLocationlong =location.getLongitude(); prefLocation = getSharedPreferences("myLocation", MODE_WORLD_READABLE); SharedPreferences.Editor prefsEditor = prefLocation.edit(); prefsEditor.putString("Lat", String.valueOf(userLocationLat)); prefsEditor.putString("Long", String.valueOf(userLocationlong)); gs.setLatitude(userLocationLat); gs.setLangitude(userLocationlong); List&lt;Address&gt; addresses; try { addresses = new Geocoder(SearchDishoom.this, Locale.getDefault()) .getFromLocation(userLocationLat, userLocationlong, 1); Address obj = addresses.get(0); add = obj.getAddressLine(0); city = obj.getLocality(); addressString = add + "," + city; gs.setCurrentAddressString(addressString); prefsEditor.putString("Address", addressString); prefsEditor.commit(); tvLocation.setText(add + "," + city); } catch (IOException e) { showToast("Unable to find location"); } } </code></pre> <p>Even i am not getting location using <code>Geocoder</code>, If i enter city name then it show me "Unable to find location".<br> Here is trick, <code>GeoCoder</code> is working on Emulator but not working on phone(i tried 2 different handset). </p> <p>My project is build in <code>API 17</code> and no any logcat error.<br> Please give me any hint or reference. </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