【问题标题】:Get CLLocation coordinate from a method从方法中获取 CLLocation 坐标
【发布时间】:2011-03-10 16:59:27
【问题描述】:

我遵循http://www.vellios.com/2010/08/16/core-location-gps-tutorial/ 的教程 制作一个应用程序来显示用户的当前位置。 它有一个名为 locationUpdate 的方法

- (void)locationUpdate:(CLLocation *)location {
    //locLabel.text = [location description];
    speedLabel.text = [NSString stringWithFormat:@"SPEED: %f", [location speed]];
    latitudeLabel.text = [NSString stringWithFormat:@"LATITUDE: %f", location.coordinate.latitude];
    longitudeLabel.text = [NSString stringWithFormat:@"LONGITUDE: %f", location.coordinate.longitude];
    altitudeLabel.text = [NSString stringWithFormat:@"ALTITUDE: %f", [location altitude]];
}

如何在这个方法之外调用 location.coordinate.latitude?​​p>

【问题讨论】:

    标签: ios core-location cllocationmanager


    【解决方案1】:

    在您的 .h 文件中创建一个 CLLocation 变量,然后在位置更新时设置该变量(在下面的方法中)。

    - (void)locationUpdate:(CLLocation *)location

    【讨论】:

    • 喜欢这个CLLocation *currentLat; ?
    • 是的,这是正确的。记得在.h中导入mapkit
    • 我如何在 viewDidLoad() 中分配它
    • 我在答案- (void)locationUpdate:(CLLocation *)location中发布的方法中没有
    • 如果对您有用,请选择正确的答案。
    猜你喜欢
    • 2014-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多