2014-01-20 43 views
0

我想獲得一個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

'self.currentlocation = ...'行是否實際執行?比較這樣的浮點值是不可靠的。相反,請檢查_currentLocation是否爲零。這就是David P所說的(「if」條件不起作用)。 – Anna

回答

1

嘗試用「無」替換0。 現在如果語句檢查,如果你的變量是空的,而不是如果它是0.

+0

我不認爲你理解我的問題。我的問題是我想保持self.currentlocation的價值。 – user2924482

0

我解決我的問題,使用CLLocationCoordinate2D存儲self.mapView.userLocation.location中的coordenates存儲。