title: Requesting nearest city in android
body: <p>I need to calculate the near city in an android app using only the Network provider.
  I manage to do it with the following code but it turns the app very slow and it works only sometimes.</p>
  
  <pre><code>
  
  public Locator(final Context c) {
  
          LocationManager locationManager = (LocationManager) c.getSystemService(Context.LOCATION_SERVICE);
          Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
          Geocoder gcd = new Geocoder(c, Locale.getDefault());
          List addresses;
          try {
              addresses = gcd.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
              if (addresses.size() > 0) {
                  if(addresses.get(0).getLocality()!=null){
                      Locator.setCity(addresses.get(0).getLocality());
                  }
              }
          }
          catch (IOException e) {
              e.printStackTrace();
          }       
      }
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>Thanks in advance.</p>