【问题标题】:Track distance travelled by user by CLLocationManager or GoogleMap-IOS通过 CLLocationManager 或 GoogleMap-IOS 跟踪用户行进的距离
【发布时间】:2014-09-26 22:35:36
【问题描述】:

我正在使用 GoogleMap-IOS-1.8.1 SDK 来显示地图。我必须计算用户走过的步行距离。搜索后我会尝试使用CLLocationManager的方法-

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

double new_travelled_distance = [newLocation distanceFromLocation:oldLocation];
total_distanceTravelled_by_user += new_travelled_distance;  }

并像这样初始化-

-(void)viewDidLoad{

[super viewDidLoad];

if(!locationManager)
{
    locationManager = [[CLLocationManager alloc] init];
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    [locationManager setDelegate:self];
    [locationManager setDistanceFilter:5.0f];         // measured in meters
    [locationManager setHeadingFilter:kCLHeadingFilterNone];            // measured in degrees
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
}
[locationManager startUpdatingLocation];   }

但这并不能提供准确的数据,即使我坐在同一个地方也没有走一米,但它可以让我定期更新以更改位置。我是否必须更正“ CLLocationManager's distanceFilter ”属性,或者我可以做些什么来更准确地计算行进距离......?

【问题讨论】:

  • Location Manager 每次都会更新,即使你闲着也不行,但是如果你移动的话,oldlocation 和 newlocation 数据会有所不同,否则两者将是相同的,所以你在 locationmanager 委托函数中的计算应该是 on检查 oldlocaion!=newlocation 是否。
  • 好的,如果距离差大于DistanceFilter,我也可以检查didUpdateToLocation方法,只有我会添加。但是这个方法只有在距离差不小于DistanceFilter时才会被调用。但我的主要问题是它的波动比DistanceFilter(= 5 米)更多。
  • 解决了吗?我这里也有这个问题!

标签: ios cllocationmanager google-maps-sdk-ios gmsmapview


【解决方案1】:

这是因为您将所需的精度设置为kCLLocationAccuracyBestForNavigation。只需删除该行。此外,heading 的默认值设置为 1,这是非常准确的。不要将其设置为kCLHeadingFilterNone

这将阻止定期更新,只有当你移动 5 米时你才会得到它。

【讨论】:

  • 还没有帮助,我想要尽可能高的精度,并且与 distanceFilter 属性的冲突更少,这就是我使用 kCLLocationAccuracyBestForNavigation 的原因。在删除“kCLLocationAccuracyBestForNavigation”或使用 kCLLocationAccuracyBest 时,我的距离波动更大,无需步行。
猜你喜欢
  • 1970-01-01
  • 2012-06-04
  • 1970-01-01
  • 2013-01-02
  • 2014-07-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多