Ovo je code
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
lm = [[CLLocationManager alloc] init];
if([lm locationServicesEnabled])
{
lm.delegate = self;
lm.desiredAccuracy = kCLLocationAccuracyBest;
lm.distanceFilter = kCLDistanceFilterNone;
[lm startUpdatingLocation];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
lm = [[CLLocationManager alloc] init];
if([lm locationServicesEnabled])
{
lm.delegate = self;
lm.desiredAccuracy = kCLLocationAccuracyBest;
lm.distanceFilter = kCLDistanceFilterNone;
[lm startUpdatingLocation];
}
}
U sustini ova metoda didUpdateToLocation mi se nikada ne poziva.
Code:
- (void) locationManager: (CLLocationManager *) manager
didUpdateToLocation: (CLLocation *) newLocation
fromLocation: (CLLocation *) oldLocation{
NSString *lat = [[ NSString alloc] initWithFormat:@"%g", newLocation.coordinate.latitude];
txtLatitude.text = lat;
NSString *lng = [[NSString alloc] initWithFormat:@"%g", newLocation.coordinate.longitude];
txtLongitude.text = lng;
NSString *acc = [[NSString alloc] initWithFormat:@"%g", newLocation.horizontalAccuracy];
txtAccuracy.text = acc;
[acc release];
[lat release];
[lng release];
}
- (void) locationManager: (CLLocationManager *) manager
didUpdateToLocation: (CLLocation *) newLocation
fromLocation: (CLLocation *) oldLocation{
NSString *lat = [[ NSString alloc] initWithFormat:@"%g", newLocation.coordinate.latitude];
txtLatitude.text = lat;
NSString *lng = [[NSString alloc] initWithFormat:@"%g", newLocation.coordinate.longitude];
txtLongitude.text = lng;
NSString *acc = [[NSString alloc] initWithFormat:@"%g", newLocation.horizontalAccuracy];
txtAccuracy.text = acc;
[acc release];
[lat release];
[lng release];
}