setAccuracy
指示所需的纬度和经度精度。如果期望的位置合适,则精度可以为ACCURACY_FINE,否则为ACCURACY_COARSE。更加精确的位置可能会消耗更多功率,并且可能需要更长的时间。
setHorizontalAccuracy
指示所需的水平精度(纬度和经度)。精度可以是ACCURACY_LOW,ACCURACY_MEDIUM,ACCURACY_HIGH或NO_REQUIREMENT。更加精确的位置可能会消耗更多功率,并且可能需要更长的时间。
原始android文档的另一个示例。那么区别是什么呢 ?注意它们采用不同的常量-是否可以/希望通过常量的组合来指定两者?
最佳答案
source很清楚。
/**
* 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()
。因此,内部准确性只是“水平准确性”。现在,如果有人知道他们为什么同时需要两者,我将接受他/她的回答-现在结束。