2014-11-24 57 views
0

這個問題一直困擾着我一段時間:我的地圖,當我在我的iOS設備上運行時,無論何時滾動到我的iOS設備,都開始回到用戶位置看看我最近放棄的另一個針腳。奇怪的是,最近纔開始這樣做。iOS 8 - 地圖不斷重新回到用戶位置

這裏是我的代碼爲:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.searchBar.delegate = self; 
    self.locationManager = [[CLLocationManager alloc] init]; 
    self.locationManager.delegate = self; 

    if ([self.locationManager respondsToSelector:@selector 
    (requestWhenInUseAuthorization)]) { 
    [self.locationManager requestWhenInUseAuthorization]; 
    mapView.showsUserLocation = YES; 
    } 
    [self.locationManager startUpdatingLocation]; 
} 

#pragma mark cllocation delegate methods 
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations: 
(NSArray *)locations 
{ 
NSLog(@"location info object=%@",[locations lastObject]); 
[self.locationManager stopUpdatingLocation]; 
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location Success" 
message:@"Location  
received" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 
[alert show]; 
} 

我如何能處理用戶的位置問題的任何想法?

回答

0

您的代碼表示:

mapView.showsUserLocation = YES; 

這意味着,地圖視圖是跟蹤用戶位置。它想繼續展示它。如果您希望地圖視圖停止執行此操作,請停止跟蹤用戶位置。

通常,您將調整MKUserTrackingMode。做最簡單的方法就是提供一個MKUserTrackingBarButtonItem。

此外,請確保您沒有在其他地方設置地圖區域。如果你不小心,設置地圖區域可以防止滾動地圖。

+0

Matt的回答是正確的,MapView正在跟蹤用戶的位置。缺少的部分是如何阻止這一點。爲了阻止它跟蹤用戶的位置,當你告訴你的locationManager stopUpdatingLocation時,嘗試設置showsUserLocation爲NO。試試看看會發生什麼。 – 2014-11-24 19:40:16

+0

這個答案正確嗎? 'showsUserLocation'只是控制是否顯示當前位置註釋。如果'userTrackingMode'設置爲'MKUserTrackingModeNone',那麼地圖不應該放大到用戶 – Paulw11 2014-11-24 20:28:45

+0

@ Paulw11您是否真的讀過我的回答?這就是我所說的:「通常,你會調整MKUserTrackingMode。」問題是用戶跟蹤模式是_not_'MKUserTrackingModeNone'。它是'MKUserTrackingModeFollow'。因此,它隨之而來。 – matt 2014-11-24 21:34:42

相關問題