當前位置: 首頁>>代碼示例>>Java>>正文


Java Address.getThoroughfare方法代碼示例

本文整理匯總了Java中android.location.Address.getThoroughfare方法的典型用法代碼示例。如果您正苦於以下問題:Java Address.getThoroughfare方法的具體用法?Java Address.getThoroughfare怎麽用?Java Address.getThoroughfare使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.location.Address的用法示例。


在下文中一共展示了Address.getThoroughfare方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getLocationName

import android.location.Address; //導入方法依賴的package包/類
/**
 * @param activity the activity requesting the location name
 * @param location the device's current location
 * @return the name of the device's current location if found, or LocationUtilities.NO_LOCATION_NAME otherwise
 */
public static String getLocationName(Activity activity, Location location){

    String name = NO_LOCATION_NAME;

    if (location != null) {
        Geocoder geocoder = new Geocoder(activity);
        try {
            Address address = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1).get(0);
            name = address.getThoroughfare();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return name;
}
 
開發者ID:CMPUT301F17T15,項目名稱:CIA,代碼行數:22,代碼來源:LocationUtilities.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


注:本文中的android.location.Address.getThoroughfare方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。