CLOSE SEARCH

CoreLocation Sample : Getting current location

LatLonSample

– (void)viewDidLoad {

[super viewDidLoad];


locationManager = [[CLLocationManager alloc] init];

locationManager.delegate = self;

locationManager.desiredAccuracy = kCLLocationAccuracyBest;

locationManager.distanceFilter = 200;


[locationManager startUpdatingLocation];

}


– (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

{

[manager stopUpdatingLocation];


latitudeLabel.text = [NSString stringWithFormat:@”%f”, newLocation.coordinate.latitude];

longitudeLabel.text = [NSString stringWithFormat:@”%f”, newLocation.coordinate.longitude];

}



– (void)dealloc {

[locationManager release];

[super dealloc];

}

Filed under: iOS