Android如何使用GPS lastknownlocation IFF Location ChangedListener赢得';跑不动
我有一个服务,运行这个线程来获取GPS坐标Android如何使用GPS lastknownlocation IFF Location ChangedListener赢得';跑不动,android,multithreading,gps,listener,coordinates,Android,Multithreading,Gps,Listener,Coordinates,我有一个服务,运行这个线程来获取GPS坐标 LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); GpsListener gpsLocationListener = new GpsListener(); long minTime = 5000; // 5 sec for test purposes... float minDistance = 1; lm.r
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
GpsListener gpsLocationListener = new GpsListener();
long minTime = 5000; // 5 sec for test purposes...
float minDistance = 1;
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime,
minDistance, gpsLocationListener);
当然,我的gpsLocationListener
如下所示:
class GpsListener implements LocationListener{
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
latitude = location.getLatitude();
longitude = location.getLongitude();
//float speed = location.getSpeed();
checkin();
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
}
}
其中,onLocationChanged
方法在获得纬度和经度后将其发送到服务器
不幸的是,这种方法并不像我在测试中希望的那样可靠,我基本上是站起来四处走动,看看它是否记录了我的位置发生了变化
如果某个函数在X秒内未更新,如何使其运行。这个不同的函数只发送最后已知的坐标
感谢您的真知灼见 您需要设置一个定期计时器。可能会帮助你做你想做的事