简体   繁体   English

CLLocationCoordinate2D转换返回null

[英]CLLocationCoordinate2D converting return null

im trying to convert longituude and latitude to NSNumbers to save them in core data. 我试图将经纬度转换为NSNumbers以将其保存在核心数据中。

following my code: 按照我的代码:

getting coordinate 得到协调

CLLocationCoordinate2D coordinate = [[mapView.annotations objectAtIndex:0] coordinate];
    NSLog(@"Long2: %f", coordinate.longitude);
    NSLog(@"Lat2: %f", coordinate.latitude);

Output 输出量

2013-04-28 20:22:05.918 [1892:16a03] Long2: -122.406417
2013-04-28 20:22:05.918 [1892:16a03] Lat2: 37.785834

Setting values: 设定值:

[members.eventDTO setLatLong:coordinate];
- (void)setLatLong: (CLLocationCoordinate2D)coordinate{
    self.locLatitude = [NSNumber numberWithDouble:coordinate.latitude];
    self.locLongitude = [NSNumber numberWithDouble:coordinate.longitude];
}

then i tried that for output: 然后我尝试输出:

NSLog(@"Long2: %f", [members.eventDTO.locLongitude doubleValue]);
NSLog(@"Lat2: %@", members.eventDTO.locLatitude);

2013-04-28 20:22:05.918 [1892:16a03] Long2: 0.000000
2013-04-28 20:22:05.919 [1892:16a03] Lat2: (null)

any clue its returning that? 任何线索返回吗?

According to what you described in your question, it seems that the object is still nil after you set it in your setLatLong: method. 根据您在问题中描述的内容,在setLatLong:方法中设置对象后,该对象似乎仍然为零。 My hints that I can suggest here are: 我的建议是:

  • try to log the NSNumber inside your setLatLong: method to check if they are being created correctly; 尝试将NSNumber记录在setLatLong:方法中,以检查是否正确创建了它们;
  • try to log self.locLatitude and self.locLongitude after you set them, to see if they are assigned correctly. 设置它们后,尝试记录self.locLatitude和self.locLongitude,以查看是否已正确分配它们。
  • are the NSManagedObject being created correctly? NSManagedObject是否被正确创建?
  • are you calling save to your NSManagedObjectContext? 您在调用保存到您的NSManagedObjectContext吗?

Please post more info so we can hunt the problem together ;) 请发布更多信息,以便我们一起解决问题;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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