Example usage for android.location Address getSubAdminArea

List of usage examples for android.location Address getSubAdminArea

Introduction

In this page you can find the example usage for android.location Address getSubAdminArea.

Prototype

public String getSubAdminArea() 

Source Link

Document

Returns the sub-administrative area name of the address, for example, "Santa Clara County", or null if it is unknown

Usage

From source file:com.kubotaku.android.openweathermap.lib.util.GeocodeUtil.java

/**
 * Get location name from Address./*w  w w .  j  av  a  2  s  .  c om*/
 * <p/>
 * Use Android Geocode class.
 * <p/>
 *
 * @param context Context.
 * @param locale  Locale.
 * @param latlng  Address.
 * @return Location name of target address.
 */
@Deprecated
public static String pointToName(final Context context, final Locale locale, final LatLng latlng) {
    String name = "";

    try {
        Geocoder geocoder = new Geocoder(context, locale);
        List<Address> addressList = null;
        try {
            addressList = geocoder.getFromLocation(latlng.latitude, latlng.longitude, 1);
        } catch (IOException e) {
            e.printStackTrace();
        }

        if ((addressList != null) && !addressList.isEmpty()) {

            int loopNum = addressList.size();
            for (int i = 0; i < loopNum; i++) {
                Address address = addressList.get(i);

                name = address.getLocality();
                if ((name == null) || (name.length() == 0)) {
                    name = address.getSubAdminArea();
                    if ((name != null) && (name.length() != 0)) {
                        break;
                    }
                } else {
                    break;
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return name;
}

From source file:com.googlecode.android_scripting.jsonrpc.JsonBuilder.java

private static JSONObject buildJsonAddress(Address address) throws JSONException {
    JSONObject result = new JSONObject();
    result.put("admin_area", address.getAdminArea());
    result.put("country_code", address.getCountryCode());
    result.put("country_name", address.getCountryName());
    result.put("feature_name", address.getFeatureName());
    result.put("phone", address.getPhone());
    result.put("locality", address.getLocality());
    result.put("postal_code", address.getPostalCode());
    result.put("sub_admin_area", address.getSubAdminArea());
    result.put("thoroughfare", address.getThoroughfare());
    result.put("url", address.getUrl());
    return result;
}

From source file:com.RSMSA.policeApp.OffenceReportForm.java

public String getAddress(double lat, double lng) {
    Geocoder geocoder = new Geocoder(OffenceReportForm.this, Locale.getDefault());
    String address = "";
    try {//from   w  w  w  .  jav a  2s. com
        List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
        Address obj = addresses.get(0);
        String add = "";
        if (obj.getAdminArea() != null) {
            add = add + obj.getAdminArea();
        }
        if (obj.getSubAdminArea() != null) {
            add = add + ", " + obj.getSubAdminArea();
        }
        if (obj.getAddressLine(0) != null) {
            add = add + ", " + obj.getAddressLine(0);
        }
        address = add;

        Log.v("IGA", "Address" + add);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {

    }
    return address;
}