Android GPS 提供商的问题:更新太多
尽管我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以设置一个距离。如果解决不了,可以看: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