gpt4 book ai didi

ios - 地理围栏 iOS 6

转载 作者:可可西里 更新时间:2023-11-01 06:23:35 25 4
gpt4 key购买 nike

我正在创建一个应用程序,告诉用户他们是否在目的地附近。我正在计算 currentLocation 和目的地之间的距离。我在 didUpdateLocations 中进行计算。它正在工作,但我已经看到有一些方法可以在不需要做任何数学运算的情况下处理它。

我正在 CLLocationManager 中注册区域;但是似乎没有调用方法 didExitRegiondidEnterRegion

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

- (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 中的区域监控功能时需要注意一些事项。

  • 无论您将初始半径设置为多少,区域都将默认为最小尺寸。一位 Apple 工程师告诉我,对于支持 GPS 的设备,它是 100M。 450M 仅适用于支持区域监控的 Wifi 设备(iPad 3 和新的 iPod Touch)
  • 您可以监控的区域有限。单个设备上可以监控的总数是有限的。同样,一位 Apple 工程师告诉我它大约有 100 个区域。使用委托(delegate)方法来确保您的地区添加的好坏。
  • 区域非常有用,对电池生命周期的影响很小。他们还在状态栏中获得自己的位置图标。 (空心紫色定位箭头)
  • 它们的工作方式与所有其他位置 API 非常相似,您需要正确响应委托(delegate)方法以解释正在发生的操作。

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

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

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

关于ios - 地理围栏 iOS 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12720658/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com