【问题标题】:Geofencing is not working properly地理围栏无法正常工作
【发布时间】:2014-05-20 05:46:59
【问题描述】:

在我的应用程序中,我想做地理围栏。我有位置列表,我正在为其设置地理围栏区域。 所有位置的半径为 100m。以下是设置Region的代码:

CLLocationCoordinate2D cord;
cord.latitude = [location.latitude doubleValue];
cord.longitude = [location.longtitude doubleValue];
CLLocationDistance regionRadius = location.radius;
CLRegion *region  = [[CLRegion alloc] initCircularRegionWithCenter:cord radius:regionRadius identifier:[NSString stringWithFormat:@"%d",location.locId]];
[appDelegate.locationManager startMonitoringForRegion:region];

我的问题是,它不能正常工作。为了调试,在 didEnterRegion 委托中添加了当前位置和区域位置之间的距离计算,有时这个距离大于 1500m

以下是计算当前位置与区域位置之间距离的代码:

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
    CLLocation *loc1 = locationManager.location;
    CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:region.center.latitude longitude:region.center.longitude];
    double dist = [loc1 distanceFromLocation:loc2];
}

知道吗,为什么-locationManager:didEnterRegion: 会以这种错误的方式触发?

【问题讨论】:

    标签: ios cllocationmanager geofencing


    【解决方案1】:

    这是 iOS 区域监控 中的一个小故障,我在 地理围栏 中遇到了类似的问题,并且我找到了解决该问题的方法。

    我已经在这里发布了这个问题,我已经回答了自己,我也有一篇关于此的博客文章:-

    1. Region Monitoring Glitch on iOS 7 - Multiple Notifications at the same time
    2. iOS Region Monitoring and Location Manager

    【讨论】:

    • 感谢瑞奇的回答。正如您建议检查当前位置和区域一样,我通过距离计算来做到这一点。您是否找到了位置管理器这种错误行为的任何原因?
    • 没问题。您可以使用 [theRegion containsCoordinate:theLocationCoordinate]; 在触发事件之前再次确认它是否真的在区域内。我在各种网站上上下搜索,我找不到任何东西。我相信这可能是由于某些国家可能发生的大半径(准确度)位置不好。我无法确认这一点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-22
    • 2013-11-12
    • 2019-01-11
    • 1970-01-01
    • 2015-05-13
    • 2016-08-16
    相关资源
    最近更新 更多