get Admin Area from Location - Android Map

Android examples for Map:Location

Description

get Admin Area from Location

Demo Code


//package com.java2s;
import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import java.io.IOException;
import java.util.List;
import java.util.Locale;

public class Main {
    public static String getAdminArea(Context context, Location location) {
        Geocoder geocoder = new Geocoder(context, Locale.getDefault());
        double latitude = location.getLatitude();
        double longitude = location.getLongitude();
        List<Address> addresses = null;
        try {/* w w  w . j  a  va 2 s.  co  m*/
            addresses = geocoder.getFromLocation(latitude, longitude, 1);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return addresses.get(0).getAdminArea();
    }
}

Related Tutorials