当前位置: 首页>>代码示例>>Java>>正文


Java Address.getSubLocality方法代码示例

本文整理汇总了Java中android.location.Address.getSubLocality方法的典型用法代码示例。如果您正苦于以下问题:Java Address.getSubLocality方法的具体用法?Java Address.getSubLocality怎么用?Java Address.getSubLocality使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.location.Address的用法示例。


在下文中一共展示了Address.getSubLocality方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSimplifiedAddress

import android.location.Address; //导入方法依赖的package包/类
/**
 * @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;
}
 
开发者ID:SoftprodigyIndia,项目名称:AndroidAppBoilerplate,代码行数:34,代码来源:LocationHelper.java

示例2: getCompleteAddress

import android.location.Address; //导入方法依赖的package包/类
/**
 * @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;
}
 
开发者ID:SoftprodigyIndia,项目名称:AndroidAppBoilerplate,代码行数:44,代码来源:LocationHelper.java

示例3: getLanguageString

import android.location.Address; //导入方法依赖的package包/类
@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;
}
 
开发者ID:fekracomputers,项目名称:MuslimMateAndroid,代码行数:31,代码来源:MosquesActivity.java


注:本文中的android.location.Address.getSubLocality方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。