0
我使用MKUserTrackingModeFollowWithHeading,以便地圖跟隨用戶位置並旋轉。問題是縮放級別不堅持。這裏是我的代碼MKUserTrackingModeFollowWithHeading,zoom
-(void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.locMapView.delegate = self;
[self.locMapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:YES];
}
-(void) viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
MKMapPoint pt = MKMapPointForCoordinate(_locMapView.userLocation.coordinate);
double w = MKMapPointsPerMeterAtLatitude(_locMapView.userLocation.coordinate.latitude) * 500;
MKMapRect zoomRect = MKMapRectMake(pt.x - w/2.0, pt.y - w/2.0, w, w);
[_locMapView setVisibleMapRect:zoomRect animated:YES];
}
我試圖設置縮放級別viewDidLoad中也沒有多少運氣。
當UserTrackingMode設置爲MKUserTrackingModeFollowWithHeading時,如何使地圖粘到縮放級別?
與您的問題無關,但您不需要計算MKMapRect以設置地圖顯示的內容。使用MKCoordinateRegionMakeWithDistance可以更容易地直接使用座標和米。它返回一個MKCoordinateRegion,你可以使用setRegion而不是調用setVisibleMapRect。 – Anna
謝謝你指出。 – user3117208