我试图将longituude和latitude转换为NSNumbers以将它们保存在核心数据中。
关注我的代码:
获得坐标
CLLocationCoordinate2D coordinate = [[mapView.annotations objectAtIndex:0] coordinate];
NSLog(@"Long2: %f", coordinate.longitude);
NSLog(@"Lat2: %f", coordinate.latitude);
输出
2013-04-28 20:22:05.918 [1892:16a03] Long2: -122.406417
2013-04-28 20:22:05.918 [1892:16a03] Lat2: 37.785834
设置值
[members.eventDTO setLatLong:coordinate];
- (void)setLatLong: (CLLocationCoordinate2D)coordinate{
self.locLatitude = [NSNumber numberWithDouble:coordinate.latitude];
self.locLongitude = [NSNumber numberWithDouble:coordinate.longitude];
}
然后我尝试输出:
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)
它返回的任何线索?
答案 0 :(得分:0)
根据您在问题中描述的内容,在您使用setLatLong:
方法设置对象后,该对象似乎仍为零。我在这里建议的提示是:
setLatLong:
方法中记录NSNumber,以检查它们是否正确创建; 请发布更多信息,以便我们可以一起解决问题;)