问题:
onLocationChanged位置有时在静止几秒后不会更新
说明:listener
开始工作后,我移动设备,位置会更新。然后我站着不动,不动。在那之后,我继续前进。它记录的内容不会改变,它会记录相同的位置。
手机和Android版:Samsung S6,Android 6.0.1
示例日志:(静止之前)
onLocationChanged: new location (60.98367243212177, 25.638220444285892)
onLocationChanged: new location (60.98367227235308, 25.638231264557437)
onLocationChanged: new location (60.98367068663074, 25.638241549966416)
(静止不动后)
onLocationChanged: new location (60.983707386852174, 25.63813532475042)
onLocationChanged: new location (60.983707386852174, 25.63813532475042)
onLocationChanged: new location (60.983707386852174, 25.63813532475042)
onLocationChanged: new location (60.983707386852174, 25.63813532475042)
我启动监听器的功能:
public void startLocationListener(){
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
MyLocationListener locationListener = new MyLocationListener();
if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1,0,locationListener);
}
LocationListener类:
private final class MyLocationListener implements android.location.LocationListener{
@Override
public void onLocationChanged(Location location) {
Log.d(TAG, "onLocationChanged: new location (" + location.getLatitude() +", " + location.getLongitude()+")");
}
@Override
public void onProviderDisabled(String provider) {
Log.d(TAG, "onProviderDisabled: ");
}
@Override
public void onProviderEnabled(String provider) {
Log.d(TAG, "onProviderEnabled: ");
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d(TAG, "onStatusChanged: " + provider + " status " + status+ "extra " + extras.toString());
}
}
这不会一直发生,我认为它可能与卫星或手机有关。有人对此有任何想法吗?提前谢谢。