iOS我怎样才能获得处于持久状态的CLLocation
问题描述:
我想获得一个CLLocation属性来存储位置MKMapView。我的这部分代码:iOS我怎样才能获得处于持久状态的CLLocation
在我的.h
@财产(保留,非原子)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的价值?
我真的很感谢你的帮助。
答
尝试用“无”替换0。 现在如果语句检查,如果你的变量是空的,而不是如果它是0.
+0
我不认为你理解我的问题。我的问题是我想保持self.currentlocation的价值。 – user2924482
答
我解决我的问题,使用CLLocationCoordinate2D存储self.mapView.userLocation.location中的coordenates存储。
'self.currentlocation = ...'行是否实际执行?比较这样的浮点值是不可靠的。相反,请检查_currentLocation是否为零。这就是David P所说的(“if”条件不起作用)。 – Anna