【问题标题】:iOS CLLocation property doesn't retain valueiOS CLLocation 属性不保留值
【发布时间】:2014-01-20 00:37:08
【问题描述】:

我正在尝试将 self.mapView.userLocation.location 保存在内存中 CLLocation 属性中,但是在我将值分配给该属性并检查该属性的值后,我得到了这个:

<+0.00000000,+0.00000000> +/- 0.00m (speed -1.00 mps / course -1.00) @ 1/19/14 4:21:14

这是我的代码:

.h:

@property (retain, nonatomic) CLLocation *currentlocation;

在我的.m上

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    if (self.currentlocation != self.mapView.userLocation.location)
    {
       self.currentlocation = self.mapView.userLocation.location;
    }

}

我的问题是谁能保留 self.currentlocation 上 self.mapView.userLocation.location 的值并将其保留在内存中?

非常感谢您的帮助。

【问题讨论】:

  • 你把mapView的showUserLocation设置为true了吗?
  • 是的,self.mapView.showsUserLocation = YES;

标签: ios iphone mkmapview xcode5 cllocation


【解决方案1】:

您正在将一个指针分配给另一个指针。因此,您实际上只是存储了对 MKUserLocation 位置的引用。

听起来您当时想存储该值,而不希望它改变。如果是这样:

 self.currentLocation = [self.mapView.userLocation.location copy];

保存一份副本应该可以得到你想要的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-28
    • 2020-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-16
    • 1970-01-01
    相关资源
    最近更新 更多