无法在iOS上获取位置 - 不会调用委托方法

时间:2013-02-04 16:56:20

标签: ios delegates location locationmanager

iOS 6下的locationManager出现问题。

-(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;
}

我在所有委托方法中都有断点,但没有一个被调用。 有人知道我做错了什么吗?或者我如何找出错误的位置?

我会感激每一个答案! 谢谢!

1 个答案:

答案 0 :(得分:0)

您是在设备上还是在模拟器中测试?在模拟器中,您必须从模拟器应用程序菜单中手动设置一些位置。它在Debug / Location /.