Geofencing iOS 6 [英] Geofencing iOS 6

查看:154
本文介绍了Geofencing iOS 6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个应用程序,告诉用户他们是否在目的地附近。
我正在计算 currentLocation 与目的地之间的距离。我正在 didUpdateLocations 中进行计算。它正在工作,但我已经看到有一些方法可以解决这个问题而无需进行任何数学运算。

I am creating an app that tells the user whether they are near the destination. I am calculating the distance between the currentLocation and the destination. I'm doing the calculation inside the didUpdateLocations. It is working but I've seen that there are methods that can deal with that without the need of doing any math.

我在<$ c中注册该区域$ C> CLLocationManager ;但似乎没有调用方法 didExitRegion didEnterRegion

I am registering the region in the CLLocationManager; however it seems that the methods didExitRegion and didEnterRegion are not been called.

以下是我注册区域的代码部分:

Here are the part of the code where I register the region:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [self.locationManager startUpdatingLocation];
    [self.mySearchBar resignFirstResponder];
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];

    self.distToRemind = 0;

    [worldMap removeAnnotations:[worldMap annotations]];
    NSLog(@"executou de primeira");

    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
        [geocoder geocodeAddressString:[self.mySearchBar text] completionHandler:^(NSArray *placemarks, NSError *error)
         {
             CLPlacemark *placemark = [placemarks lastObject];

             //test
             //DefaultAnnotation *annot = [[DefaultAnnotation alloc] initWithCoordinate:placemark.location.coordinate andTitle:@""];
             CLRegion *newRegion = [[CLRegion alloc] initCircularRegionWithCenter:placemark.location.coordinate radius:10.0 identifier:@"RegionBoundary"];

             DefaultAnnotation *regionAnnotation = [[DefaultAnnotation alloc] initWithCoordinate:newRegion.center andTitle:@""];

             [self identifyPlacemark:placemark andSetAnnotation:regionAnnotation];

             MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(regionAnnotation.coordinate, 250, 250);


             [worldMap addAnnotation:regionAnnotation];
             [worldMap setRegion:region animated:YES];

             [self.locationManager startMonitoringForRegion:newRegion];

             if (self.boolPushButtonTapped) {
                  [self pushButtonTapped];
             }
         }
         ];
}

我在这里做错了吗?

推荐答案

好的,在iOS中使用区域监控功能时要记住一些事项。

Ok, a few things to keep in mind when using the region monitoring ability in iOS.


  • 无论您将初始半径设置为何,区域都将默认为最小大小。一位Apple工程师告诉我,支持GPS的设备是100M。 450M仅支持Wifi设备支持区域监控(iPad 3和新iPod Touch)

  • 您可以监控的区域是有限的商品。可以在单个设备上监控的总数是有限的。同样,一位Apple工程师告诉我它大约有100个地区。使用委托方法确保您的区域添加好或坏。

  • 区域非常有用,对电池寿命影响最小。他们还在状态栏中获取自己的位置图标。 (空心紫色位置箭头)

  • 它们与其他所有位置API非常相似,您需要正确响应委托方法以解释正在发生的操作。

  • Regions are going to default to the minimum size no matter what you set the initial radius to. An Apple engineer told me it is 100M for GPS enabled devices. 450M for Wifi only devices that support region monitoring (iPad 3 and new iPod Touches)
  • Regions you can monitor are a limited commodity. The total number that can be monitored on a single device is limited. Again, an Apple engineer told me it is around 100 regions. Use the delegate methods to make sure your region was added good or bad.
  • Regions are very useful and have minimal impact on battery life. They also get their own location icon in the status bar. (hollow purple location arrow)
  • They work very much like every other location API, you need to respond to the delegate methods correctly to interpret the actions that are happening.

您的代码看起来不错,但缺少 CLLocationManagerDelegate 的逻辑。如果没有合适的委托来处理回调,你可能只是错过了回调( -didExitRegion / -didEnterRegion )。

Your code looks good but is missing the logic surrounding your CLLocationManagerDelegate. Without a proper delegate to handle the callbacks, you are likely just missing the callbacks ( -didExitRegion/-didEnterRegion).

根据我的经验,我创建了一个单例类来处理我的所有位置管理器委托方法。请务必注册以收听他们。如果你包含一些围绕这些委托电话的代码,我很乐意为你提供更多帮助。有很多教程应该记录如何正确设置它们。祝你好运。

In my experience, I create a singleton class to handle all of my location manager delegate methods. Make sure you sign up to listen for them. If you include some more code surrounding those delegate calls, I'd be glad to help you more. There are plenty of tutorials out there that should document how to set them up correctly. Good luck.

*注意:我今年在WWDC与位置工程师谈过了很多关于最小区域大小和区域数量的未知数。我可以确认最小区域大小为100,但不是最大区域数。到目前为止我还没有这个需要。

*Note: I spoke to a location engineer at WWDC this year about a lot of these unknowns surrounding min region size and number of regions. I can confirm the min region size at 100, but not the max number of regions. I haven't had the need as of yet.

这篇关于Geofencing iOS 6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆