title: Easy way to get city from LocationManager on Android?
body: <p>I'm trying to figure out the city of where the user is using their location. Using LocationManager and Geocoder I get some nice data from the longitude and latitude, but I can't get one thing. The subAdminArea a.k.a. the city. It always returns <strong>null</strong> for me, even though everything else including the postal code is received. Is there something I am missing?</p>
  
  <p>Basically this is a method I call for getting data.</p>
  
  <pre><code>public String getLocation(Locale locale, Context context, boolean city, boolean postal, boolean state_prov) throws IOException{
      LocationManager locMan = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
      LocationListener locList = new MyLocList();
      Geocoder gC = new Geocoder(context,locale);
      Location gpsLocation = locMan.getLastKnownLocation(locMan.GPS_PROVIDER);
      locMan.requestLocationUpdates(locMan.NETWORK_PROVIDER, 500, 200, locList);
      Location networkLocation = locMan.getLastKnownLocation(locMan.NETWORK_PROVIDER);
      if (city)
          return (gC.getFromLocation(networkLocation.getLatitude(), networkLocation.getLongitude(), 1).get(0).getSubAdminArea());
      else if (postal)
          return (gC.getFromLocation(networkLocation.getLatitude(), networkLocation.getLongitude(), 1).get(0).getPostalCode());
      else if (state_prov)
          return (gC.getFromLocation(networkLocation.getLatitude(), networkLocation.getLongitude(), 1).get(0).getAdminArea());
      else
          return "";
  }
  </code></pre>
  
  <p>and the call to this method is done via:</p>
  
  <pre><code>String city = getLocation(Locale.getDefault(),getBaseContext(),true,false,false);
  </code></pre>
  
  <p>The only other option I have found through some research is sending a request to </p>
  
  <pre><code>http://maps.googleapis.com/maps/api/geocode/json?address=POSTALCODE&amp;sensor=true
  </code></pre>
  
  <p>and it gives me a JSON of that location based on the postal code, which I can then parse, but it seems like a lot of work to find the city.</p>
  
  <p>Could there be something I am missing? Or something I did wrong? I am new to location services for android.</p>