Tag: cllocationmanager

将CLLocationCoordinate2D存储到NSUserDefaults

我是新的iphone开发,我想存储CLLocationCoordinate2D对象到NSUserDefaults 。 我在尝试 [defaults setObject:location forKey:@"userLocation"]; 但它给出了错误'发送CLLocationCoordinate2D参数的不兼容的typesID' 那么如何将CLLocationCoordinate2D存储到NSUserDefaults ? 谢谢。

需要获得超过20个地区监测通知

我正在开发一个应用程序,用户可以设置多个位置。 当用户进入或离开特定位置边界时,我会成功显示通知。 现在,我需要为所有已保存的位置提供监视,并且可能会有数百个和更多的情况。 我已经阅读了苹果论坛和许多iOS设备只允许20区域监测。 我已经开发了我的代码来超越这种情况。 我已经设置了locationManager.distanceFilter = 200; 当我得到更新的位置。 首先,我停止了所有区域监测,并根据最近位置的条件,再次启动20个保存位置的区域监测。 我认为上述解决scheme可能会导致在停止时丢失任何保存的位置,并再次重新启动区域监视。 所以,请给我提供任何其他更好的解决scheme来解决这个区域监测问题的20个通知。 祝你今天愉快 。!!..

蓝色横幅“%MyApp%正在使用您的位置”仅适用于在活动状态下使用位置服务的应用

在我的应用程序中,每当应用程序变为活动状态时,我都更新用户位 一旦收到更新的位置,或者在applicationWillResignActive:我停止CLLocationManager 。 在Info.plist有一个NSLocationWhenInUseUsageDescription有适当的描述。 如果应用程序被激活,然后立即移动到后台,蓝色的横幅说'%MyApp%使用您的位置'出现不到一秒钟。 这个横幅一旦被隐藏applicationWillResignActive:被调用。 我注意到了Google地图中的相同问题,但在Apple Maps中却没有。 有没有办法彻底摆脱这个旗帜? 还有什么我应该做的,使iOS快乐? 我不希望它吓坏我的用户,并阻止他们使用需要位置的酷炫function。

didEnterRegion工作在前台,但不是后台或其他VC

如果应用程序正在运行,并且CLLocationManagerDelegate类是前景(即可见),则会触发didEnterRegions,并同时获得NSLog和AlertView。 但是,当应用程序处于后台时,我什么也得不到,实质上,如果屏幕显示除委托类以外的任何内容。 我已经在plist的“所需的背景模式”下设置了“位置更新的应用程序寄存器”,尽pipe我不确定这是甚至是必要的。 这是我认为是相关的代码,虽然我可能是错的(并很乐意添加更多)。 我应该注意,viewDidLoad中的所有内容都包含在一个if中,以检查区域监视是否可用和启用。 – (void)viewDidLoad { NSLog(@"MapViewController – viewDidLoad"); self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; self.locationManager.distanceFilter = kCLLocationAccuracyNearestTenMeters; self.locationManager.delegate = self; [self.locationManager startMonitoringSignificantLocationChanges]; } – (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region { NSLog(@"MapViewController – didEnterRegion"); NSLog(@"MVC – didEnterRegion – region.radius = %f", region.radius); UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"entered region…" message:@"You have Entered the Location." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: […]

didUpdateLocations未被调用

我试图得到我当前的位置,但didUpdateLocations中的断点永远不会被调用。 的LocationManager: locationManager = [[CLLocationManager alloc] init]; [locationManager setDelegate:self]; [locationManager setDesiredAccuracy:kCLLocationAccuracyBest]; [locationManager setDesiredAccuracy:kCLDistanceFilterNone]; [locationManager startUpdatingLocation]; 代表方法: – (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations; 我确认位置服务并启用和授权。 为什么不调用locationManager委托方法? 谢谢,迈克

如何检查MKCoordinateRegion是否包含CLLocationCoordinate2D而不使用MKMapView?

我需要检查用户位置是否属于MKCoordinateRegion。 我很惊讶没有find简单的函数, 像这样:CGRectContainsCGPoint(矩形,点) 。 我发现下面的一段代码: CLLocationCoordinate2D topLeftCoordinate = CLLocationCoordinate2DMake(region.center.latitude + (region.span.latitudeDelta/2.0), region.center.longitude – (region.span.longitudeDelta/2.0)); CLLocationCoordinate2D bottomRightCoordinate = CLLocationCoordinate2DMake(region.center.latitude – (region.span.latitudeDelta/2.0), region.center.longitude + (region.span.longitudeDelta/2.0)); if (location.latitude < topLeftCoordinate.latitude || location.latitude > bottomRightCoordinate.latitude || location.longitude < bottomRightCoordinate.longitude || location.longitude > bottomRightCoordinate.longitude) { // Coordinate fits into the region } 但是,我不确定是否准确,因为文档没有明确指定区域矩形的计算方式。 必须有更简单的方法来做到这一点。 我忽略了MapKit框架文档中的一些function吗?

Swift 2 – 不能用CLLocationManager获取用户位置

这是我的VC代码: import UIKit import MapKit import CoreLocation class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate { @IBOutlet weak var mapView: MKMapView! let locationManager = CLLocationManager() override func viewDidLoad() { super.viewDidLoad() locationManager.delegate = self locationManager.requestWhenInUseAuthorization() mapView.showsUserLocation = true } func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) { mapView.showsUserLocation = (status == .AuthorizedAlways) } func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { […]

ios定期获取我的位置,并设置button来获取我的位置 – 谷歌地图不工作

我正在使用Google Map Module,使用1.9.0 Bundle来定期查找我的位置,比如说10秒钟,并创build一个button来获取我的位置button作为一个地图视图设置 当执行和位置服务打开时,单击右下angularbutton后没有响应,位置pipe理器不工作。 我可以显示使用位置服务的任何迹象。 我不知道我在设置这个地图上缺less什么,因为我严格遵循SDKDemos – iOS的谷歌演示项目来设置我的模块。 你能告诉我确切的方法来设置它吗? 以下是我的代码: @implementation MapViewController -(bool)isNetworkAvailable { SCNetworkReachabilityFlags flags; SCNetworkReachabilityRef address; address = SCNetworkReachabilityCreateWithName(NULL, "www.apple.com" ); Boolean success = SCNetworkReachabilityGetFlags(address, &flags); CFRelease(address); bool canReach = success && !(flags & kSCNetworkReachabilityFlagsConnectionRequired) && (flags & kSCNetworkReachabilityFlagsReachable); return canReach; } – (void)requestAlwaysAuthorization { CLAuthorizationStatus status = [CLLocationManager authorizationStatus]; // If […]

为什么self.locationManager stopUpdatingLocation不停止位置更新

问题 :看来我无法阻止Core Location发送更新到我的应用程序/跟踪。 我在做什么 :在我的viewWillAppear我调用self.locationManager并传递给一个方法来显示用户在地图上的位置( MKMapView一个实例)。 getter被覆盖以检查serive的可用性,看是否授权。 如果是这样,它allocs/inits startMonitoringSignificantLocationChanges和startMonitoringSignificantLocationChanges和returns 。 在viewDidDisappear ,我调用[self.locationManager stopUpdatingLocation] 。 但是我仍然可以看到状态栏中的位置图标。 即使当我通过双击主页button并closures应用程序来终止应用程序时,即使在延长的时间(10分钟以上)之后,图标仍然存在。 当我去设置应用程序,它告诉我,我的应用程序仍在使用位置服务(紫色图标)。 问题:我在这里错过了什么? 为什么位置更新不停止? 提前致谢。

CLLocationManager授权问题iOS 8

我正在为iOS 8的一块Swift代码工作。我试图做一些涉及位置的东西,所以我已经在我的swift视图控制器文件中实现了以下内容: let locationManger:CLLocationManager = CLLocationManager() var speedReceived:Double = 0 override func viewDidLoad() { super.viewDidLoad() locationManger.delegate = self locationManger.desiredAccuracy = kCLLocationAccuracyBest let authstate = CLLocationManager.authorizationStatus() if(authstate == CLAuthorizationStatus.NotDetermined){ println("Not Authorised") locationManger.requestWhenInUseAuthorization() } // Do any additional setup after loading the view, typically from a nib. } func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!){ var location:CLLocation = […]