我只想在距离当前位置3米处移动时获取当前位置更新
FusedLocationClient.requestLocationUpdates
为此我做了这样的LocationRequest:
private LocationRequest requestLocation(){
LocationRequest mLocationRequest = new LocationRequest();
mLocationRequest.setSmallestDisplacement(3.81f);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
return mLocationRequest;
}
并实现如下:连接到播放服务后
@Override
public void onConnected(Bundle bundle) {
mFusedLocationClient.requestLocationUpdates(requestLocation(),
new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
for (final Location location : locationResult.getLocations()) {
tvLat.setText(Double.toString(location.getLatitude()));
tvLng.setText(Double.toString(location.getLongitude()));
//changing position of marker and camera
changeCameraPosition(CameraUpdateFactory.newLatLngZoom(
new LatLng(location.getLatitude(), location.getLongitude()),
16), new GoogleMap.CancelableCallback() {
@Override
public void onFinish() {}
@Override
public void onCancel() { }
});
}
}
}, Looper.myLooper());
但是我离这个距离我现在的位置至少650米远的地方,即使我没有移动,这里是我在清单中的权限:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="permission.READ_GSERVICES" />
答案 0 :(得分:0)
也许您可以查看这个:Android map Update location to server when there is difference of x meters between current location and last location并查看移动时距离的差异,这样您就会知道过度移动的来源发生在哪里。