Iphone 将nsnumber或nsstring放入initWithLatitude:
我也被卡住了,很愚蠢,我正试图把一个Iphone 将nsnumber或nsstring放入initWithLatitude:,iphone,ios,mapkit,cllocation,Iphone,Ios,Mapkit,Cllocation,我也被卡住了,很愚蠢,我正试图把一个NSString或一个NSNumber放入CLLocation的initWithLatitude。如果有人能帮忙,那就太好了 这是密码 CLLocation *location1 = [[CLLocation alloc] initWithLatitude:53.778702 longitude:-0.271887]; CLLocation *location2 = [[CLLocation alloc] initWithLatitude:53.683267
NSString
或一个NSNumber
放入CLLocation
的initWithLatitude
。如果有人能帮忙,那就太好了
这是密码
CLLocation *location1 = [[CLLocation alloc] initWithLatitude:53.778702 longitude:-0.271887];
CLLocation *location2 = [[CLLocation alloc] initWithLatitude:53.683267 longitude:-0.011330];
label.text = [NSString stringWithFormat:@"Distance in miles: %4.1f", [location1 distanceFromLocation:location2]/1609.344];
[location1 release];
我试图用经度:53.778702经度:-0.271887来代替
[[CLLocation alloc]initwithlation:lat longitude:lon]
CLLocation degrees
是一个双精度,所以你可以这样做
[[CLLocation alloc] initWithLatitude:[someNSNumber doubleValue] longitude:[someNSString doubleValue]];
为什么不使用CLLocationDegrees
数据类型来处理位置值?此类型只是普通的双精度数据类型
/*
* CLLocationDegrees
*
* Discussion:
* Type used to represent a latitude or longitude coordinate in degrees under the WGS 84 reference
* frame. The degree can be positive (North and East) or negative (South and West).
*/
typedef double CLLocationDegrees;
无论lat
和lon
是NSstring还是NSNumbers,这都有效。这非常有效,谢谢,这正是我需要的!上帝的地位仍然是有效的发现上面的例子,它现在运作良好,你说的是一个更好的方式吗?我不知道还有另一种方法。如果您的数据是NSNumber,那么您的问题不会得到解决,但仅供参考-如果您使用ARC,您需要删除[location1 release]
。编译器将为您处理该问题。
CLLocation *loc = [[CLLocation alloc] initWithLatitude: (CLLocationDegrees) [lat doubleValue] longitude: (CLLocationDegrees) [lon doubleValue]];