7
iOS App Development Q.1 Tracking Location http://iosappdev.co.kr 13년 2월 28일 목

iOS Location Tracking Basic

Embed Size (px)

Citation preview

Page 1: iOS Location Tracking Basic

iOS App Development

Q.1 Tracking Locationhttp://iosappdev.co.kr

13년 2월 28일 목

Page 2: iOS Location Tracking Basic

CLLocationManager

Core Location Framework

<CoreLocation/CoreLocation.h>

Interface for delivering Location Update

13년 2월 28일 목

Page 3: iOS Location Tracking Basic

CLLocationManagerSteps to use: Simplest Example

Instantiate - [[... alloc] init];

Setup desiredAccuracy @property

Implement and Assign a Delegate

delegate @property

CLLocationManagerDelegate

[... startUpdatingLocation]

Receive Update: CLLocation object

13년 2월 28일 목

Page 4: iOS Location Tracking Basic

CLLocationManagerInitialize and Start Updating

@interface ......@property (nonatomic, strong) CLLocationManager *locationManager;...@end// in a method // Instantiate

self.locationManager = [[CLLocationManager alloc] init]; // Setup Delegate: See Next Slide self.locationManager.delegate = self; // Setup Accuracy CLLocationAccuracy accuracy = kCLLocationAccuracyNearestTenMeters; self.locationManager.desiredAccuracy = accuracy; // Start! [self.locationManager startUpdatingLocation];...

13년 2월 28일 목

Page 5: iOS Location Tracking Basic

CLLocationManagerSetup a Delegate

@interface KMUViewController () <CLLocationManagerDelegate>......@end// in a method, before starting update ... self.locationManager.delegate = self;...

#pragma mark - CLLocationManagerDelegate- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ CLLocation *location = [locations lastObject]; CLLocationDegrees lat = location.coordinate.latitude; CLLocationDegrees lon = location.coordinate.longitude; // ... self.textField.text = [location description];}

13년 2월 28일 목

Page 7: iOS Location Tracking Basic

Testing in Simulator

http://iosappdev.co.kr

13년 2월 28일 목