1

尽管我在 requestLocatioupdate 方法中将 minTime 设置为 10 秒,但我仍然可以在不到一秒的时间内获得新位置。

 public class GpsActivity extends Activity {
LocationManager mLocationManager;
TextView mTextView;
int count;
     /** Called when the activity is first created. */
     @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mTextView = (TextView) findViewById(R.id.text);
        count = 0;
        mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 0,mGpsLocationListener);
     } 

     Handler mHandler = new Handler(){

         @Override
         public void handleMessage(Message msg){
             switch(msg.what){
             case 1:
                 mTextView.setText("new location count:"+count);
             }
         }
    };

    LocationListener mGpsLocationListener = new LocationListener(){

    @Override
    public void onLocationChanged(Location location) {
        count++;
        mHandler.sendEmptyMessage(1);

    }

    @Override
    public void onProviderDisabled(String arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderEnabled(String arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
        // TODO Auto-generated method stub

    }

    };

}

我的程序是为 android 2.2 编写的

任何的想法?

提前致谢。

4

1 回答 1

0

你可以设置一个距离。如果不解决,你可以看到:minTime通知的最小时间间隔,以毫秒为单位。此字段仅用作节省电量的提示,位置更新之间的实际时间可能大于或小于此值。minDistance 通知的最小距离间隔,以米为单位

所以我认为时间不正确,如果您希望更新 10 秒,我认为您应该使用 Time 和 TimeTask 或处理程序。或者你可以看看http://androidforums.com/developer-101/107085-proper-provider-parameter-requestlocationupdates.html

于 2011-04-12T10:43:45.373 回答