2

我也被卡住了,也很愚蠢,我正在尝试将一个或NSString一个NSNumber放入initWithLatitude. 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][[CLLocation alloc] initWithLatitude:lat longitude:lon]

4

3 回答 3

5

CLLocationDegrees是 a double,所以你做

[[CLLocation alloc] initWithLatitude:[someNSNumber doubleValue] longitude:[someNSString doubleValue]];
于 2012-08-06T22:59:03.067 回答
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;
于 2012-08-06T23:07:22.830 回答
0
CLLocation *loc = [[CLLocation alloc] initWithLatitude: (CLLocationDegrees) [lat doubleValue] longitude: (CLLocationDegrees) [lon doubleValue]];

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

于 2013-07-01T20:22:55.420 回答