我也陷入困境,我正试图将NSString
或NSNumber
放入initWithLatitude
的{{1}}。如果有人能提供帮助就会很棒。
继承代码
CLLocation
我正在尝试将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];
替换为[[CLLocation alloc] initWithLatitude:53.778702 longitude:-0.271887]
答案 0 :(得分:5)
CLLocationDegrees
是double
,所以你做
[[CLLocation alloc] initWithLatitude:[someNSNumber doubleValue] longitude:[someNSString doubleValue]];
答案 1 :(得分:0)
为什么不使用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;
答案 2 :(得分:0)
CLLocation *loc = [[CLLocation alloc] initWithLatitude: (CLLocationDegrees) [lat doubleValue] longitude: (CLLocationDegrees) [lon doubleValue]];
无论lat
和lon
是NSStrings还是NSNumbers,这都有效。