0

我使用此代码获取 gps 数据

- (void)locationUpdate:(CLLocation *)location {
    locLabel.text = [location description];
}

结果看起来像这样

<+38.76856432, +11.99454301> +/- 100.00m(速度......)

当我尝试这个时,我有一个错误,

- (void)locationUpdate:(CLLocation *)location {
    locLabel.text = [location altitude];}

错误

从不兼容的类型 CLLocationDistance(又名双精度)分配给“NSString *”

我也想得到经度

4

2 回答 2

4

您应该能够从 和 分别获得纬度和location.coordinate.latitude经度location.coordinate.longitude

您收到的海拔高度可能无效。检查 中的值location.verticalAccuracy。根据文档,“负值表示高度值无效。” location.horizontalAccuracy确保 location.coordinate 中的纬度和经度值有效也是如此。

于 2011-12-12T21:45:25.490 回答
1

altitude属性的类型CLLocationDistancetypedeffor double。您正在尝试将数字分配给需要字符串的属性。您需要创建数字的字符串表示形式。使用这样的东西:

locLabel.text = [NSString stringWithFormat:@"%f", [location altitude]];
于 2011-12-12T21:30:42.930 回答