2

设置精度

指示纬度和经度的所需精度。如果所需位置很好,则精度可能是 ACCURACY_FINE,否则可能是 ACCURACY_COARSE。更准确的位置可能会消耗更多的电量并且可能需要更长的时间。

setHorizo​​ntalAccuracy

指示所需的水平精度(纬度和经度)。准确度可以是 ACCURACY_LOW、ACCURACY_MEDIUM、ACCURACY_HIGH 或 NO_REQUIREMENT。更准确的位置可能会消耗更多的电量并且可能需要更长的时间。

原始 android 文档的另一个示例。那么区别是什么呢 ?请注意,它们采用不同的常数 - 是否可以/希望用某种常数组合来指定两者?

4

1 回答 1

2

来源比较清楚。

/**
 * Indicates the desired horizontal accuracy (latitude and longitude).
 * Accuracy may be {@link #ACCURACY_LOW}, {@link #ACCURACY_MEDIUM},
 * {@link #ACCURACY_HIGH} or {@link #NO_REQUIREMENT}.
 * More accurate location may consume more power and may take longer.
 *
 * @throws IllegalArgumentException if accuracy is not one of the supported constants
 */
public void setHorizontalAccuracy(int accuracy) {
    if (accuracy < NO_REQUIREMENT || accuracy > ACCURACY_HIGH) {
        throw new IllegalArgumentException("accuracy=" + accuracy);
    }
    mHorizontalAccuracy = accuracy;
}

/**
 * Returns a constant indicating the desired horizontal accuracy (latitude and longitude).
 * Accuracy may be {@link #ACCURACY_LOW}, {@link #ACCURACY_MEDIUM},
 * {@link #ACCURACY_HIGH} or {@link #NO_REQUIREMENT}.
 */
public int getHorizontalAccuracy() {
    return mHorizontalAccuracy;
}

/**
 * Indicates the desired accuracy for latitude and longitude. Accuracy
 * may be {@link #ACCURACY_FINE} if desired location
 * is fine, else it can be {@link #ACCURACY_COARSE}.
 * More accurate location may consume more power and may take longer.
 *
 * @throws IllegalArgumentException if accuracy is not one of the supported constants
 */
public void setAccuracy(int accuracy) {
    if (accuracy < NO_REQUIREMENT || accuracy > ACCURACY_COARSE) {
        throw new IllegalArgumentException("accuracy=" + accuracy);
    }
    if (accuracy == ACCURACY_FINE) {
        mHorizontalAccuracy = ACCURACY_HIGH;
    } else {
        mHorizontalAccuracy = ACCURACY_LOW;
    }
}

/**
 * Returns a constant indicating desired accuracy of location
 * Accuracy may be {@link #ACCURACY_FINE} if desired location
 * is fine, else it can be {@link #ACCURACY_COARSE}.
 */
public int getAccuracy() {
    if (mHorizontalAccuracy >= ACCURACY_HIGH) {
        return ACCURACY_FINE;
    } else {
        return ACCURACY_COARSE;
    }
}

那么区别是什么呢 ?请注意,它们采用不同的常数 - 是否可以/希望用某种常数组合来指定两者?

好吧,它没有区别 -setAccuracy()只需设置mHorizontalAccuracy为要么ACCURACY_HIGH-ACCURACY_LOW如果您愿意ACCURACY_MEDIUM,或者NO_REQUIREMENT您必须调用setHorizontalAccuracy()

所以内部精度只是“水平精度”。现在,如果有人知道他们为什么需要两者,我会接受他/她的回答-暂时关闭。

于 2013-12-17T21:18:18.273 回答