Tag: cllocationmanager

Swift:用户位置附近的Geofencing / geolocations

问题: 我试图让它始终使用用户的位置,并不断检查它是否在我设置的CLLocationCoordinate2D点的5英里内。 如果是这样,则在应用程序打开时发送警报,或者在应用程序closures时发送通知。 有用的信息: 在我的项目中,我有4个快速文件: Locations.swift包含CLLocationCoordinate2D点。 Utilities.swift包含一个简单的警报。 UserLocation.swift检索并更新用户的位置 GeoLocationViewController.swift监视位置 注意: 一些代码可能不在正确的位置或相关,我在看另一个项目,试图从它提取相关的代码来使用我的项目。 请告诉我,如果你发现一个错误。 码: Locations.swift: import UIKit import MapKit class Locations: UIViewController { override func viewDidLoad() { super.viewDidLoad() var radius: CLLocationDistance = 5 let arroyo = CLLocationCoordinate2D (latitude: 33.781327997137595, longitude: -116.46394436519012) var arroyoCoord: CLLocationCoordinate2D = arroyo let buddyrogers = CLLocationCoordinate2D (latitude: 33.78051204742721, longitude: -116.46362250010833) var buddyCoord: […]

如何陷阱的位置警报响应iphone

我在iPhone上使用GPS,它显示使用位置服务的构造消息。 我想陷入用户select“允许”或“否”。 任何人可以build议我如何做到这一点? 谢谢

如何从一个方法返回多个值

我有 – (CLLocationCoordinate2D)方法,我想从该方法返回多个位置(这些位置正在使用另一种方法)我的方法看起来像这样, -(CLLocationCoordinate2D) addressLocation{ – ——– ———- return location; } 是否有可能返回多个位置(我的意思是返回 location1, 返回 location2 ..)?? 请帮助我谢谢

iOS Geofence,监控开始时如何处理内部区域?

我一直无法解决如何处理手机已经在区域内的情况下startMonitoringForRegion被称为? 其他问题已经build议在didStartMonitoringForRegion调用requestStateForRegion然后调用方法didDetermineState: forRegion: 所以代码看起来像这样: – (void)viewDidLoad { //location manager set up etc… for (Object *object in allObjects){ CLRegion *region = [self geofenceRegion:object]; [locationManager startMonitoringForRegion:region]; } } – (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region { [self.locationManager requestStateForRegion:region]; [self.locationManager performSelector:@selector(requestStateForRegion:) withObject:region afterDelay:5]; } – (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region { if (state == CLRegionStateInside){ [self locationManager:locationManager didEnterRegion:region]; } } […]

获取半径内的位置

我正在开发iOS应用程序,我想在其中查找某个半径内的所有位置。 在objective-c中有什么办法可以让我指定一个固定的半径和位置,这将告诉我哪个位置在这个半径内? 我做了一些研究,我得到了这个代码片段, – (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { CLGeocoder *geocoder = [[CLGeocoder alloc] init]; [geocoder reverseGeocodeLocation:locationManager.location completionHandler:^(NSArray *placemarks, NSError *error) { NSLog(@"reverseGeocodeLocation:completionHandler: Completion Handler called!"); if (error) { NSLog(@"Geocode failed with error: %@", error); return; } CLLocationDistance radius = 30; CLLocation* target = [[CLLocation alloc] initWithLatitude:51.5028 longitude:0.0031]; NSArray *locationsWithinRadius = [placemarks objectsAtIndexes: […]

locationManager:didFailWithError:如果用户位置服务closures,则不会调用

从locationManager的文档:didFailWithError: 如果用户拒绝您的应用程序使用位置服务,则此方法会报告kCLErrorDenied错误。 一旦收到这样的错误,你应该停止位置服务。 当用户按“不允许”问题时,“MyApp会使用您的当前位置”,因此您可以pipe理这种可能性。 但是,当用户按“取消”问题“打开位置服务以允许”MyApp“以确定您的位置”时(如果位置服务被closures,则会出现此消息。 有没有办法有任何forms的callback?

捕获用户位置:澄清

我有一个应用程序捕获用户的位置,并将这个信息发送到我的服务器。 我已经开始使用LocationManager服务: – (CLLocationManager *)locationManager { if (_locationManager == nil) { _locationManager = [[CLLocationManager alloc] init]; _locationManager.delegate = self; isUpdatingLocation = NO; } return _locationManager; } -(void) startLookingForLocation{ [self locationManager].desiredAccuracy = kCLLocationAccuracyBest; [self locationManager].distanceFilter = 250; if([[self locationManager]respondsToSelector:@selector(setPausesLocationUpdatesAutomatically:)]) [[self locationManager] setPausesLocationUpdatesAutomatically:YES]; if([[self locationManager]respondsToSelector:@selector(setActivityType:) ]) [[self locationManager] setActivityType:CLActivityTypeFitness]; [[self locationManager] startUpdatingLocation]; [[self locationManager] startUpdatingHeading]; isUpdatingLocation = […]

iOS从后台重新检查加载位置

我正在构build一个应用程序,根据您当前的位置显示结果数据。 目前,我使用UIViewController的viewDidLoad方法来启动CLLocationManager并获取当前位置。 一旦我的位置符合我所希望的准确性,我会向我的Web服务请求获取结果并将其转储到UITableView 。 我的问题是,当你closures应用程序(尽pipe它仍然在后台运行)。 如果您要开车到另一个城镇,请重新打开应用程序,数据不会更新,并继续显示旧位置的结果。 基本上,当UIViewController从后台加载,我需要能够检查用户的位置,如果他们已经移动了很长的距离,更新我的UITableView的内容。 但是,因为UIViewController的viewDidAppear没有被触发,当你从后台加载应用程序,我不知道我可以使用哪种方法。 我知道stopMonitoringSignificantLocationChanges方法,它会在find新的位置时唤醒您的应用程序。 不过,这似乎有点OTT,因为我只需要知道应用程序加载。 有没有其他select使用stopMonitoringSignificantLocationChanges方法?

iOS:为什么“启用位置服务”警报在启动时显示两次?

当我禁用位置服务时,此警报显示两次。 第一次没有显示位置pipe理器目的属性。 紧接着(在第一次提醒button被触摸之前),它再次显示,这次包括目的属性。 当第二个警报解除时,第一个警报仍然存在。 这有点烦人,我希望它会让用户感到困惑。 我可以做些什么只显示一次,目的属性?

Geofencing iOS 6

我正在创build一个应用程序,告诉用户他们是否在目的地附近。 我正在计算currentLocation和目的地之间的距离。 我正在做didUpdateLocations里面的didUpdateLocations 。 它正在工作,但我已经看到,有一些方法可以处理,而不需要做任何的math计算。 我正在注册CLLocationManager的区域; 但是,似乎didExitRegion和didEnterRegion方法没有被调用。 以下是我注册地区的部分代码: – (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:@""]; […]