Example usage for android.location Address getSubLocality

List of usage examples for android.location Address getSubLocality

Introduction

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

Prototype

public String getSubLocality() 

Source Link

Document

Returns the sub-locality of the address, or null if it is unknown.

Usage

From source file:Main.java

public static String getAddressString(List<Address> addresses) {
    String locality = null;// w ww  .ja  v a 2  s.  c o  m

    for (Address address : addresses) {
        String subLocality = address.getSubLocality();
        if (subLocality != null || locality == null) {
            locality = address.getLocality();
        }

        if (subLocality != null && locality != null) {
            return String.format("%s, %s", subLocality, locality);
        }
    }

    return locality;
}

From source file:com.yayandroid.utility.MapHelperFragment.java

/**
 * Parses found address object from GeoCoder, and posts informations
 *//*from w ww  .  ja va  2 s .  c  om*/
private void parseAddressInformation(Address address) {

    /**
     * This parsing also may need to be modified up to your country's
     * addressing system
     */

    String value = address.getSubLocality();
    if (value != null)
        PostInformation(LocInfoType.COUNTY, value);

    value = address.getLocality();
    if (value != null)
        PostInformation(LocInfoType.LOCALITY, value);

    value = address.getAdminArea();
    if (value != null)
        PostInformation(LocInfoType.CITY, value);

    value = address.getCountryName();
    if (value != null)
        PostInformation(LocInfoType.COUNTRY, value);

    // If there is still some fields to get information about, then post
    // googleMap api to get them
    boolean isThereAnyLeft = false;
    for (int i = 0; i < requiredInformations.length; i++) {
        if (!requiredInformations[i].hasSent) {
            isThereAnyLeft = true;
        }
    }

    if (isThereAnyLeft)
        fetchInformationUsingGoogleMap();

}