Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.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
Cocoa 将CLLocationCoordinate2D类型转换为数字或字符串_Cocoa_Cllocation - Fatal编程技术网

Cocoa 将CLLocationCoordinate2D类型转换为数字或字符串

Cocoa 将CLLocationCoordinate2D类型转换为数字或字符串,cocoa,cllocation,Cocoa,Cllocation,我想知道如何将CLLocationCoordinate2D的纬度和经度值转换为数字或字符串值。 Iver尝试了几种不同的方法,但都不起作用: CLLocationCoordinate2D centerCoord; centerCoord.latitude = self.locModel.userLocation.coordinate.latitude ; centerCoord.longitude = self.locModel.userLocation.coordinate.longitude

我想知道如何将CLLocationCoordinate2D的纬度和经度值转换为数字或字符串值。 Iver尝试了几种不同的方法,但都不起作用:

CLLocationCoordinate2D centerCoord;
centerCoord.latitude = self.locModel.userLocation.coordinate.latitude ;
centerCoord.longitude = self.locModel.userLocation.coordinate.longitude; 
NSString *tmpLat = [[NSString alloc] initWithFormat:@"%g", centerCoord.latitude];
NSString *tmpLong = [[NSString alloc] initWithFormat:@"%g", centerCoord.longitude];

NSLog("User's latitude is: %@", tmpLat);
NSLog("User's longitude is: %@", tmpLong);
这将返回编译器发出的警告

警告是

warning: passing argument 1 of 'NSLog' from incompatible pointer type
我该怎么做

任何帮助都将不胜感激


谢谢

您没有提到警告是什么,但很可能是因为您忘记了NSLog字符串前面的
@

NSLog(@"User's latitude is: %f", self.locModel.userLocation.coordinate.latitude );
NSLog(@"User's longitude is: %f", self.locModel.userLocation.coordinate.longitude );
您的更新代码应为:

NSLog(@"User's latitude is: %@", tmpLat);
NSLog(@"User's longitude is: %@", tmpLong);

NSLog需要一个NSString参数,该参数前面需要一个@符号。如果没有@符号,字符串是普通的C字符串而不是NSString对象。

安娜·卡列尼娜(Anna Karenina)对此感到困惑,很抱歉。我已经更新了我的问题信息并添加了警告。请参见上文,谢谢。问题确实在于NSLog字符串前面没有@符号。