2013-08-24 51 views
3

我正在製作一個應用程序來顯示用戶當前位置附近的一些位置。當用戶移動地圖時,地圖會一次又一次地將用戶移動到當前位置。因此,用戶無法在地圖上看到註釋,因爲如果他移動地圖,地圖會返回到其當前位置。當用戶移動地圖時,停止MKMapView移動到用戶當前位置

這就是我現在在做什麼:

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation 
{ 
if (userLocation) 
{ 
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 1000, 1000); 
    MKCoordinateRegion regionDelMapa = [self.mapa regionThatFits:region]; 
    if(isnan(regionDelMapa.center.latitude)) 
    { 
     NSLog(@"Bad region..."); 
    }else 
    { 
     [self.mapa setRegion:regionDelMapa animated:YES]; 
    } 
} 
} 

我在這裏嘗試了一些其他的答案,但沒有任何反應。這不是所需的行爲,所以我該如何停止更新用戶的當前位置?

回答

3
[self.mapa setRegion:regionDelMapa animated:YES]; 

該行設置地圖區域。每次獲取更新時都會執行該代碼,從而重新設置地圖覆蓋的區域。如果您不希望地圖在每次更新時重新定位到用戶的位置,請從-mapView:didUpdateUserLocation:方法中刪除該代碼。

如果您想將地圖放在用戶上一次,然後允許用戶從該位置滾動離開,請使用核心位置獲取用戶的位置。

1

請使用此API:[locationManager stopUpdatingLocation]; 將此功能添加到您的功能didUpdateUserLocation

相關問題