Skip to content

Instantly share code, notes, and snippets.

@ekoneil
Created November 13, 2012 06:27
Show Gist options
  • Save ekoneil/4064293 to your computer and use it in GitHub Desktop.
Save ekoneil/4064293 to your computer and use it in GitHub Desktop.
MDD CLLocationManager Code Snippets
CLLocationManagerDelegate
@property (strong, nonatomic) CLLocationManager *locationManager;
@property (strong, nonatomic) FBCacheDescriptor *placeCacheDescriptor;
// Get the CLLocationManager going.
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
// We don't want to be notified of small changes in location, preferring to use our
// last cached results, if any.
self.locationManager.distanceFilter = 50;
[self.locationManager startUpdatingLocation];
- (IBAction)clickPlace:(id)sender {
FBPlacePickerViewController* vc = [[FBPlacePickerViewController alloc]init];
[vc configureUsingCachedDescriptor:self.placeCacheDescriptor];
[vc loadData];
[vc presentModallyFromViewController:self animated:YES handler:^(FBViewController *sender, BOOL donePressed) {
if(donePressed) {
NSLog(@"Success");
}
}];
}
-(void)locationManager:manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
if (!oldLocation ||
(oldLocation.coordinate.latitude != newLocation.coordinate.latitude &&
oldLocation.coordinate.longitude != newLocation.coordinate.longitude &&
newLocation.horizontalAccuracy <= 100.0)) {
// Fetch data at this new location, and remember the cache descriptor.
self.placeCacheDescriptor =
[FBPlacePickerViewController cacheDescriptorWithLocationCoordinate:newLocation.coordinate
radiusInMeters:1000
searchText:nil
resultsLimit:50
fieldsForRequest:nil];
[self.placeCacheDescriptor prefetchAndCacheForSession:FBSession.activeSession];
}
}
-(void)locationManager:manager didFailWithError:(NSError *)error {
NSLog(@"Error! %@", error);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment