【问题标题】:iOS how can I get CLLocation in persistent stateiOS如何让CLLocation处于持久状态
【发布时间】:2014-01-21 09:41:01
【问题描述】:

我正在尝试获取 CLLocation 属性来存储位置 MKMapView。我的这部分代码:

在我的 .h 上

@property (retain, nonatomic) CLLocation *currentlocation;

在我的.m上

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{

    if ((_currentlocation.coordinate.longitude == 0 ) && (_currentlocation.coordinate.latitude == 0) )
    {
        self.currentlocation = [self.mapView.userLocation.location copy];
}

问题是每次尝试更新“self.currentlocation”为0的位置。我的问题是如何保留self.currentlocation的值?

非常感谢您的帮助。

【问题讨论】:

  • self.currentlocation = ... 行真的在执行吗?像这样比较浮点值是不可靠的。相反,检查 _currentLocation 是否为零。这就是 David P 所说的(if 条件不起作用)。

标签: ios iphone cllocation


【解决方案1】:

尝试将 0 替换为“nil”。 现在 if 语句检查你的变量是否为空,而不是 0。

【讨论】:

  • 我认为你没有理解我的问题。我的问题是我想保留 self.currentlocation 的值。
【解决方案2】:

我使用 CLLocationCoordinate2D 将坐标存储在 self.mapView.userLocation.location 中解决了我的问题。

【讨论】:

    猜你喜欢
    • 2021-04-21
    • 2017-11-19
    • 1970-01-01
    • 2022-06-28
    • 2010-11-20
    • 2012-08-06
    • 2022-01-21
    • 2011-01-09
    • 1970-01-01
    相关资源
    最近更新 更多