嗨,我已经在服务中实现了Fused Location提供程序API以获取位置更新。我能够按照设置的时间间隔触发onlocationchanged事件。但是,当我将setsmallestDisplacement设置为10米时,即使设备静止,事件也会被触发。是否有人遇到类似的问题?请提出建议。以下是代码:
mlocationrequest = LocationRequest.create();
mlocationrequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mlocationrequest.setInterval(60000); // Update location every 1 minute
mlocationrequest.setFastestInterval(10000);
mlocationrequest.setSmallestDisplacement(10);
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mlocationrequest, this);
为了找到两个位置值之间的距离,我使用了这种方法。
public static float distFrom (float lat1, float lng1, float lat2, float lng2 )
{
double earthRadius = 3958.75;
double dLat = Math.toRadians(lat2-lat1);
double dLng = Math.toRadians(lng2-lng1);
double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
Math.sin(dLng/2) * Math.sin(dLng/2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
double dist = earthRadius * c;
int meterConversion = 1609;
return new Float(dist * meterConversion).floatValue();
}
即使设备静止,我测得的距离为43.51、49.32、520.02。这是因为我在室内使用平板电脑吗?