Een zeer verkorte versie:
In de eerste plaats vast te stellen het <CLLocationManagerDelegate>protocol in je .h, en #import <CoreLocation/CoreLocation.h>.
Toen in .m go:
- (void)viewDidLoad {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
CLLocationCoordinate2D here = newLocation.coordinate;
NSLog(@"%f %f ", here.latitude, here.longitude);
}
Uw -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocationmethode krijgt gepingeld elke keer Core Location heeft iets te zeggen, dat om de paar seconden zou moeten gebeuren. die CLLocation objecten bevatten informatie over de nauwkeurigheid, dus je kunt het scherm voor goede punten in die methode.
Wees er zeker van te bellen [locationManager stopUpdatingLocation]en dan [locationManager release]op een gegeven moment!
Good luck het vinden van jezelf!