我有一個MKMapView
在我所設置:的iOS的MKMapView - 從重新中心到用戶的位置,如果用戶已經平移停止地圖視圖/拖動地圖視圖
[self.mapView setShowsUserLocation:YES];
我想告訴用戶位置,如果他/她移動,則更新位置。當didUpdateUserLocation
被調用時,似乎地圖重新集中到用戶的位置,即使用戶已將應用程序平移到另一個區域。我想要的是能夠跟蹤用戶的位置,但也讓用戶探索地圖。我didUpdateUserLocation
目前看起來是這樣的:
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
_currentLocation = userLocation;
[self.mapView setRegion:MKCoordinateRegionMake(CLLocationCoordinate2DMake(self.currentLocation.coordinate.latitude + 0.0015, self.currentLocation.coordinate.longitude), MKCoordinateSpanMake(0.01, 0.01)) animated:NO];
[...]
}
上我應該做的,以達到我想要的是什麼任何想法?
謝謝。你知道一種設置MKMapView縮放級別而不設置區域的方法嗎?我希望它與用戶非常接近。而且我只知道'didUpdateUserLocation'後的'_currentLocation'。 – Anders
我通過添加BOOL ivar來解決它,只在'didUpdateUserLocation'中設置'setRegion'一次。 – Anders
如果您想要設置放大區域,而不是以用戶位置爲中心的區域,則可以使用region屬性獲取地圖的實際顯示區域。 您將擁有CLLocationCoordinate2D中心和MKCoordinateSpan跨度。通過保持中心和修改中心,您可以更改zoomLevel。 只需使用setRegion設置新的區域:動畫:並且你有你的縮放:) –