location Address - Android Map

Android examples for Map:Address

Description

location Address

Demo Code


import android.content.Context;
import android.location.Address;
import android.location.Criteria;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationManager;
import java.io.IOException;
import java.util.List;

public class Main{
    public static String location2Address(Location loc, Context context) {
        Geocoder gc = new Geocoder(context);
        List<Address> list;
        Address addressAndroid;/*from   w  w w.j  a v  a2s .c om*/
        String address = null;
        if (loc != null) {
            try {
                list = gc.getFromLocation(loc.getLatitude(),
                        loc.getLongitude(), 1);
                for (int idx = 0; idx < list.size(); idx++) {
                    addressAndroid = list.get(idx);
                    //http://developer.android.com/reference/android/location/Address.html
                    address = addressAndroid.getAddressLine(idx)
                            +
                            Constants.CONCATDELIMETER
                            + addressAndroid.getLocality() +
                            "";
                }
            } catch (IOException e) {
                Common.logError("LocationUtils location2Address IOException: "
                        + e.getMessage());
                //e.printStackTrace();
            }
        }
        return address;
    }
}

Related Tutorials