0
这是我第一次开发应用程序。所以我希望用户的坐标以及地址在用户按下视图控制器中的'查看位置'按钮时显示。locationManager startUpdatingLocation崩溃应用程序
我已经编码了所有内容,当我在模拟器中按下按钮时,它突然关闭,并将我指向IBAction按钮方法中的[newlocationManager startUpdatingLocation]代码。它说“线程:1断点1.1”。这是什么意思,我该如何解决它?
这是我的接口文件:
@interface FirstViewController : UIViewController <CLLocationManagerDelegate>
@property (weak, nonatomic) IBOutlet UILabel *latitudeLabel;
@property (weak, nonatomic) IBOutlet UILabel *longitudeLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
- (IBAction)getCurrentLocation:(id)sender;
@end
,这是我实现文件:
#import "FirstViewController.h"
@interface FirstViewController()
@end
#pragma - UIViewController // Categorizes a group of methods
@implementation FirstViewController{
//The CCLocationManager is the object that provides the location data and the methods.
CLLocationManager * newlocationManager;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
newlocationManager = [[CLLocationManager alloc] init];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma - IBAction // Categorizes a group of methods
- (IBAction)getCurrentLocation:(id)sender {
newlocationManager.delegate = self;
newlocationManager.desiredAccuracy = kCLLocationAccuracyBest;
[newlocationManager startUpdatingLocation];
}
#pragma - CLLocationManagerDelegate // Categorizes a group of methods
// Informs the delegate that it was unable to get location data. Displays error pop-up alert.
- (void) locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
// The error why location could not be retreived
NSLog(@"didFailWithError: %@", error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
}
- (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
// Last object of the 'locations' array contains the most recent location. newLocation now points to the last object.
CLLocation *newLocation = [locations lastObject];
CLLocation *oldLocation;
// Check the size of the NSArray (locations). If it contains a single object, just set oldLocation to nil.
// If it contains more than 1 object then store that in oldLocation.
if (locations.count>1){
oldLocation = [locations objectAtIndex:(locations.count - 2)];
}
else
oldLocation = nil;
NSLog(@"didUpdateToLocation %@ from %@", newLocation, oldLocation);
if (newLocation != nil){
_longitudeLabel.text = [NSString stringWithFormat:@"%.8f", newLocation.coordinate.longitude];
_latitudeLabel.text = [NSString stringWithFormat:@"%.8f", newLocation.coordinate.latitude];
}
//MKCoordinateRegion userLocation = MKCoordinateRegionMakeWithDistance(newLocation.coordinate, 1500.0, 1500.0);
//[regionsMapView setRegion:userLocation animated:YES];
}
@end
你得到了什么错误?如果你变弱变强可能会有所帮助。 – Bejibun 2014-10-07 22:20:32
删除调试器中的断点或在停止后单击“继续”按钮。 – rmaddy 2014-10-07 22:22:10