Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 将nsnumber或nsstring放入initWithLatitude:_Iphone_Ios_Mapkit_Cllocation - Fatal编程技术网

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