嗨我已经实现了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);
Run Code Online (Sandbox Code Playgroud)
为了找到两个位置值之间的距离,我使用了这种方法.
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 …Run Code Online (Sandbox Code Playgroud)