我每次要求更新位置时都应该使用android LocationManager.getBestProvider吗?

Or *_*zaz 10 android locationmanager android-mapview

我正在使用Google API和MapActivity,MapView等.
当我需要获取当前位置时,我会在第一时间使用此代码:

myLocationManager =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
// Sets the criteria for a fine and low power provider
Criteria crit = new Criteria();
crit.setAccuracy(Criteria.ACCURACY_FINE);
crit.setPowerRequirement(Criteria.POWER_LOW);    
// Gets the best matched provider, and only if it's on
String provider = myLocationManager.getBestProvider(crit, true);
// If there are no location providers available
if (provider == null){
    OnClickListener listener = new OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            // Closes the activity
            finish();
        }
    };
    Utils.getInstance().showAlertDialog(this, R.string.warning_dialog_title,
                               R.string.no_location_providers_error_message,
                            android.R.drawable.ic_dialog_alert, false, listener);
}
// Location services is enabled
else{
    myLocationListener = new MyLocationListener();
    myLocationManager.requestLocationUpdates(
            provider,
            0,
            0,
            myLocationListener);        
    // TODO - put a marker in my location       
    GeoPoint currentGeoPoint = MapUtils.getInstance().
            getCurrentLocation(myLocationManager, provider);        
    // Center to the current location
    centerLocation(currentGeoPoint, MAX_ZOOM);
}
Run Code Online (Sandbox Code Playgroud)

我还有一个"回到当前位置按钮" - 当用户移动地图并希望快速返回其当前位置时.

我的问题是,每次我想获取位置信息时,我应该使用该getBestProvider()方法吗?

我可以保存最后一个选择的提供者,但条件可能每秒都会改变:

  1. 用户关闭了GPS
  2. 没有GPS信号
  3. 在当前情况下,NETWORK_PROVIDER更好
  4. 等等..

什么是正确的方法?

Or *_*zaz 2

就像评论中所说的那样,这就是答案: http://developer.android.com/guide/topics/location/strategies.html#BestEstimate

  • 链接损坏。这就是为什么发布链接作为答案是不好的! (2认同)