2010-06-18 115 views
0

由于某种原因我的代码导致我的程序崩溃。有谁知道为什么或如何解决它?iPhone模拟器崩溃,当它试图访问用户位置

NSLog(@"here"); 
CLLocation *location = [locationManager location]; 
[mapView removeAnnotations:mapView.annotations]; 
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
CLLocationCoordinate2D workingCoordinate = [location coordinate]; 
NSLog(@" this is %@", workingCoordinate.latitude); 

它使它成为第一个NSLog,但在第一个和第二个之间崩溃。我的猜测是它与CLLocation *位置线有关。

回答

2

CLLocationCoordinate2D是一个包含两个类型为CLLocationDegrees的非对象字段的结构体。传递给NSLog%@将尝试将该值解释为对象引用,并导致崩溃。

尝试: NSLog(@“this is%d”,workingCoordinate.latitude);

+1

允许程序工作,但它给了一个不可能的纬度:14212.在我的地图上,虽然它将这个注释的坐标添加到纬度0 long 0 – 2010-06-18 03:03:43

+0

这是因为经度和纬度是双倍的,所以你可以不使用%d,你可以使用%f格式说明符。检查[文档中的CLLocationDegrees定义](http://developer.apple.com/iphone/library/documentation/CoreLocation/Reference/CLLocation_Class/CLLocation/CLLocation.html) – progrmr 2010-06-18 03:18:00

+0

Duh。当然。谢谢。 – bbum 2010-06-18 12:36:26