Skip to content

Instantly share code, notes, and snippets.

@logicaroma
Forked from nickcharlton/gist:779831
Created April 8, 2011 13:07
Show Gist options
  • Save logicaroma/909786 to your computer and use it in GitHub Desktop.
Save logicaroma/909786 to your computer and use it in GitHub Desktop.
An Objective-C Object for LocationServices
// LocationServices.h
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
@interface LocationServices : NSObject <CLLocationManagerDelegate> {
CLLocationManager *locationManager;
CLLocation *currentLocation;
}
@property (nonatomic, retain) CLLocationManager *locationManager;
@property (nonatomic, retain) CLLocation *currentLocation;
- (void)startLocationServices;
@end
// LocationServices.m
#import "LocationServices.h"
@implementation LocationServices
@synthesize locationManager, currentLocation;
- (void)startLocationServices {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
if ([CLLocationManager locationServicesEnabled]) {
[locationManager startUpdatingLocation];
} else {
NSLog(@"Location services is not enabled");
}
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
self.currentLocation = newLocation;
NSLog(@"Latidude %@ Longitude: %@", newLocation.coordinate.latitude, newLocation.coordinate.longitude);
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
[locationManager stopUpdatingLocation];
NSLog(@"Update failed with error: %@", error);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment