Android Fused Location API在onLocationChanged中提供了不准确的位置
我在这里有点挣扎,我使用融合API来获取位置更新。我的意图是在用户行走时在地图上绘制一条路径 我已实施以下措施:Android Fused Location API在onLocationChanged中提供了不准确的位置,android,android-fusedlocation,Android,Android Fusedlocation,我在这里有点挣扎,我使用融合API来获取位置更新。我的意图是在用户行走时在地图上绘制一条路径 我已实施以下措施: @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.map_layout, container, false)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.map_layout, container, false);
// some other initialization
//....
//
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(mContext)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
return view;
}
然后我按照下面的方法开始
private void startReceivingLocationUpdates() {
if (checkGPSPermission() && mGoogleApiClient.isConnected() && !isReceivingLocationUpdates) {
LocationRequest locationRequest = new LocationRequest();
locationRequest.setInterval(5000);
locationRequest.setFastestInterval(5000);
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,
locationRequest, this);
isReceivingLocationUpdates = true;
}
}
&在这里我收到了位置更新
@Override
public void onLocationChanged(Location location) {
if(getDistanceBetweenTwoLacation(mCoordinates.get(mCoordinates.size() - 1), location) > 3d) {
for(int i= 0; i < mCoordinates.size(); i++) {
Location locationTemp = mCoordinates.get(i);
Log.d(TAG, "i => " + i + " Lat => " + String.valueOf(locationTemp.getLatitude()) + " Lng => " + String.valueOf(locationTemp.getLongitude()));
}
if(mCoordinates.size() > 0)
Log.d(TAG, "lat difference is => " + getDistanceBetweenTwoLacation(mCoordinates.get(mCoordinates.size() - 1), location));
mCoordinates.add(location);
}
}
在室内,GPS定位不准确(移动/漂移/跳跃)的情况非常普遍。没有清晰的天空视图,精确的GPS定位是不可能的。在位置
对象中,有一个getAccurance()
方法返回浮点值。该值是以米为单位的定位精度,置信度为68%(1个标准偏差),表示圆的半径
在室内,你可能会看到20米、30米、甚至50米的准确度,而横向和纵向跳远则在该距离内。一旦在户外,精确度值应该下降到10米以下,通常在5米以下,并且你的位置跳跃的频率要低得多
tl;dr:GPS在室内不能给出准确的结果。你在室内做这些测试吗?如果是这样的话,它经常跳来跳去是正常的。检查准确度值,你会发现它相当高,表明位置存在很大的不确定性。你在清单中有什么权限?@user3137702是的,我正在室内测试…@Matias Eloriaga以下是我建议尝试删除访问\u粗略\u位置权限的任务
private double getDistanceBetweenTwoLacation(Location origin, Location destination) {
return origin.distanceTo(destination);
}