在initWithLatitude中放入nsnumber或nsstring:

时间:2012-08-06 22:48:39

标签: iphone ios mapkit cllocation

我也陷入困境,我正试图将NSStringNSNumber放入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]

3 个答案:

答案 0 :(得分:5)

CLLocationDegreesdouble,所以你做

[[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]];

无论latlon是NSStrings还是NSNumbers,这都有效。