Android How to - Find Location from Geocoder








Question

We would like to know how to find Location from Geocoder.

Answer

/*from   w w w.j av a 2  s .c o m*/
import java.io.IOException;
import java.util.List;
import java.util.Locale;

import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;

public class Main {

  public static List<Address> find(Location location, Context context) {
    Geocoder geocode = new Geocoder(context, Locale.getDefault());
    try {
      List<Address> address = geocode.getFromLocation(location.getLatitude(),
          location.getLongitude(), 1);
      if (address.size() > 0) {
        return address;
      }
    } catch (IOException e) {
    }

    return null;
  }
}