Android GPS 提供商的问题:更新太多

发布于 2024-11-01 06:23:11 字数 1589 浏览 5 评论 0原文

尽管我在 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 编写的,

有什么想法吗?

提前致谢。

Although I set minTime to 10 seconds in the requestLocatioupdate method I still get new location in less than one second.

 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

    }

    };

}

My program is written for android 2.2

Any idea?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野の 2024-11-08 06:23:11

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

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

you can set a distance .if not solve,youcan see :minTime the minimum time interval for notifications, in milliseconds. This field is only used as a hint to conserve power, and actual time between location updates may be greater or lesser than this value.
minDistance the minimum distance interval for notifications, in meters

so i think the time not correct,if you hope update 10s,i think you should use Time andTimeTask,or handler. or you can look http://androidforums.com/developer-101/107085-proper-provider-parameter-requestlocationupdates.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文