2016-10-26 109 views
0

Iam开发一个应用程序,通过使用Handler每秒执行一些场信号强度计算,并且在处理程序期间它记录坐标并记录结果&坐标。它工作正常,除非真正的测试和我增加车辆的记录坐标不是每秒钟的速度,而有时每2-3-4秒不接受我。 下面的代码:位置更新


final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,  0, this); 

publicvoid method_01(LocationManager locationManager){ 

final Handler handler = new Handler(); 
handler.postDelayed(new Runnable() { 

@Override 
public void run() { 
Location locationDataRate =  locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
double latitude = locationDataRate.getLatitude(); 
double longitude = locationDataRate.getLongitude(); 
x=y+1; 
Save to file (latitude,longitude,x); 
handler.postDelayed(this, 1000); 
} 
}, 1000); 

} 

我曾尝试也改变了时间和分钟。距离(1000,0)

+0

您需要订阅位置更改 locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,2000,1f,yourListener); –

回答

0

首先,如果您希望每1秒接收一次更新,则不应请求更频繁的更新。因此:

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this); 

总之,处理位置更新的最佳做法是不是永久循环getLastKnownLocation但执行位置更新的回调。有一堆示例here

你的问题,在doc他们的状态更新之间的间隔从未保证:

的位置更新间隔可以使用minTime 参数来控制。位置更新之间所用的时间永远不会比minTime小 ,尽管它可能更多取决于位置 提供程序实现和其他 应用程序请求的更新时间间隔。