Java Code Examples for android.location.Address#getSubLocality()

The following examples show how to use android.location.Address#getSubLocality() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java    From your-local-weather with GNU General Public License v3.0 6 votes vote down vote up
public static String getCityAndCountryFromAddress(Address address) {
    if (address == null) {
        return "";
    }
    String geoCity = getCityFromAddress(address);
    String geoCountryDistrict = null;
    if(address.getAdminArea() != null) {
        geoCountryDistrict = address.getAdminArea();
    }
    String geoDistrictOfCity = address.getSubLocality();
    String geoCountryName = address.getCountryName();
    if ((geoDistrictOfCity == null) || "".equals(geoDistrictOfCity) || geoCity.equalsIgnoreCase(geoDistrictOfCity)) {
        if ((geoCountryDistrict == null) || "".equals(geoCountryDistrict) || geoCity.equals(geoCountryDistrict)) {
            return formatLocalityToTwoLines((("".equals(geoCity))?"":(geoCity)) + (("".equals(geoCountryName))?"":(", " + geoCountryName)));
        }
        return formatLocalityToTwoLines((("".equals(geoCity))?"":(geoCity + ", ")) + geoCountryDistrict + (("".equals(geoCountryName))?"":(", " + geoCountryName)));
    }
    return formatLocalityToTwoLines((("".equals(geoCity))?"":(geoCity + " - ")) + geoDistrictOfCity + (("".equals(geoCountryName))?"":(", " + geoCountryName)));
}
 
Example 2
Source File: Utils.java    From your-local-weather with GNU General Public License v3.0 5 votes vote down vote up
public static String getLocationForSharingFromAddress(Address address) {
    if (address == null) {
        return "";
    }
    String geoCity = getCityFromAddress(address);
    String geoDistrictOfCity = address.getSubLocality();
    if ((geoDistrictOfCity == null) || "".equals(geoDistrictOfCity) || geoCity.equalsIgnoreCase(geoDistrictOfCity)) {
        return geoCity;
    }
    return (("".equals(geoCity))?"":(geoCity + " - ")) + geoDistrictOfCity;
}
 
Example 3
Source File: Utils.java    From your-local-weather with GNU General Public License v3.0 5 votes vote down vote up
public static String getLocationForVoiceFromAddress(Address address) {
    if (address == null) {
        return "";
    }
    String geoCity = getCityFromAddress(address);
    String geoDistrictOfCity = address.getSubLocality();
    if ((geoDistrictOfCity == null) || "".equals(geoDistrictOfCity) || geoCity.equalsIgnoreCase(geoDistrictOfCity)) {
        return geoCity;
    }
    return (("".equals(geoCity))?"":(geoCity + " ")) + geoDistrictOfCity;
}
 
Example 4
Source File: MosquesActivity.java    From MuslimMateAndroid with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("LongLogTag")
private String getLanguageString(double LATITUDE, double LONGITUDE) {
    String lang = "Null";
    Geocoder geocoder = new Geocoder(MosquesActivity.this, Locale.getDefault());
    try {
        List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1);
        if (addresses != null) {
            Address returnedAddress = addresses.get(0);


            lang = returnedAddress.getSubLocality();

            Locale[] locales = Locale.getAvailableLocales();
            for (Locale localeIn : locales) {
                if (returnedAddress.getCountryCode().equalsIgnoreCase(localeIn.getCountry())) {
                    lang = localeIn.getLanguage();
                    break;
                }
            }
            Log.i("My Current language", "" + lang);
        } else {
            Log.w("My Current loction address", "No Address returned!");
        }
    } catch (Exception e) {
        e.printStackTrace();
        Log.w("My Current loction address", "Canont get Address!");
    }
    Log.i("KeyLang" , lang);
    return lang;
}
 
Example 5
Source File: LocationHelper.java    From SampleApp with Apache License 2.0 5 votes vote down vote up
/**
 * @param latitude  latitude of address
 * @param longitude longitude of address
 * @return simplified address of location
 */

public String getSimplifiedAddress(double latitude, double longitude) {
    String location = "";
    try {
        Geocoder geocoder = new Geocoder(mContext, Locale.getDefault());
        List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
        if (addresses.size() > 0) {
            Address address = addresses.get(0);
            String admin = address.getAdminArea();
            String subLocality = address.getSubLocality();
            String locality = address.getLocality();
            if (admin.length() > 10) {
                admin = admin.substring(0, 10) + "..";
            }
            if (locality != null && subLocality != null) {
                location = subLocality + "," + locality;
            } else if (subLocality != null) {
                location = subLocality + "," + admin;
            } else {
                location = locality + "," + admin;
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    return location;
}
 
Example 6
Source File: LocationHelper.java    From SampleApp with Apache License 2.0 5 votes vote down vote up
/**
 * @param latitude  latitude of address
 * @param longitude longitude of address
 * @return complete address of location
 */

public String getCompleteAddress(double latitude, double longitude) {
    String location = "";
    try {
        Geocoder geocoder = new Geocoder(mContext, Locale.getDefault());
        List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
        if (addresses.size() > 0) {
            Address address = addresses.get(0);
            String state, city, zip, street;
            if (address.getAdminArea() != null) {
                state = address.getAdminArea();
            } else {
                state = "";
            }
            if (address.getLocality() != null) {
                city = address.getLocality();
            } else {
                city = "";
            }
            if (address.getPostalCode() != null) {
                zip = address.getPostalCode();
            } else {
                zip = "";
            }

            if (address.getThoroughfare() != null) {
                street = address.getSubLocality() + "," + address.getThoroughfare();
            } else {
                street = address.getSubLocality() + "," + address.getFeatureName();
            }
            location = street + "," + city + "," + zip + "," + state;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    return location;
}