簡體   English   中英

當用戶移動地圖時,停止MKMapView移動到用戶的當前位置

[英]Stop MKMapView from moving to user's current location when user moves the map

我正在制作一個應用程序來顯示用戶當前位置附近的一些地方。 當用戶移動地圖時,地圖一遍又一遍地將用戶移動到他的當前位置。 因此,用戶無法在地圖上看到注釋,因為如果他移動地圖,地圖將返回到他當前的位置。

這就是我現在正在做的事情:

- (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];
    }
}   
}

我在這里嘗試了其他一些答案,但沒有任何反應。 這不是理想的行為,那么如何停止更新用戶的當前位置?

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

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

如果你想一次中心對用戶的地圖,然后允許用戶滾動從該位置時,可以使用核心定位來獲取用戶的位置。

請使用此API: [locationManager stopUpdatingLocation]; 在函數didUpdateUserLocation添加它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM