简体   繁体   中英

can't get location on iOS - doesn't call delegate methods

i have a problem with the locationManager under iOS 6.

-(void) getLocationTest {
// Create a location manager instance to determine if location services are enabled. This manager instance will be
// immediately released afterwards.

manager = [[CLLocationManager alloc] init];
if (![manager locationServicesEnabled]) {
    UIAlertView *servicesDisabledAlert = [[UIAlertView alloc] initWithTitle:@"Location Services Disabled" message:@"You currently have all location services for this device disabled. If you proceed, you will be asked to confirm whether location services should be reenabled." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [servicesDisabledAlert show];
    //[servicesDisabledAlert release];
}
manager.delegate = self;
manager.desiredAccuracy = kCLLocationAccuracyKilometer;
// Set a movement threshold for new events.
manager.distanceFilter = 500;
[manager startUpdatingLocation];

//[manager release];
}





-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
double testDe = 2.434;
testDe = testDe * 2;
}



-(void)locationManager:(CLLocationManager *)manager
 didUpdateLocations:(NSArray *)locations {
CLLocation *location = [locations objectAtIndex:0];
double locDouble = location.coordinate.latitude;
NSString* locName = [[NSString alloc] initWithFormat:@"Hello, %f!", locDouble];
//[locations lastObject];
//NSLog(@"lat%f - lon%f", location.coordinate.latitude, location.coordinate.longitude);
}


-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
double testD = 2.434;
testD = testD * 2;
}

i have breakpoints in all the delegate methods, but none of them is being called. Does someone know what i'm doing wrong? or how i can find out where the error is?

i would be grateful for every answer! thanks!

Are you testing this on a device or in the simulator? In the simulator you have to manually set some location from the simulator app menu. It's in Debug/Location/.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM