【问题标题】:Location Manager won't display latitude and longitude位置管理器不会显示纬度和经度
【发布时间】:2013-05-19 16:42:36
【问题描述】:

我有一个显示用户位置的经度和纬度的应用程序。应用程序会询问当前位置,并在 Xcode 中显示纬度和经度。但在应用程序中,什么也没有发生。

这是我的代码:

- (NSString *)deviceLocation {
    NSString *theLocation = 
        [NSString stringWithFormat:@"latitude: %f longitude: %f", 
        locationManager.location.coordinate.latitude, 
        locationManager.location.coordinate.longitude];
    return theLocation;
}

在 viewDidLoad 中:

locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];

NSLog(@"%@", [self deviceLocation]);

问题是纬度和经度标签不会显示位置。

【问题讨论】:

  • @MichaelDautermann ,这是我唯一的代码。
  • 我认为问题在于我没有将标签设置为与 locationmanager 一起使用。你能帮我解决这个问题吗?

标签: ios objective-c location latitude-longitude


【解决方案1】:

我的猜测是您没有将视图控制器作为 委托 分配给 CLLocationManager。

您可以通过以下方式做到这一点:

locationManager.delegate = self;

在您创建 locationManager 之后。

然后,您可以通过让视图控制器响应委托方法locationManager:didUpdateLocations: 来更新标签。

【讨论】:

    猜你喜欢
    • 2014-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-22
    • 1970-01-01
    相关资源
    最近更新 更多