MKUserTrackingModeFollowWithHeading,zoom

时间:2014-01-10 22:19:30

标签: ios zoom mapkit tracking

我使用MKUserTrackingModeFollowWithHeading,以便地图跟随用户位置并旋转。问题是缩放级别不粘。这是我的代码

-(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时,如何让地图坚持缩放级别?

1 个答案:

答案 0 :(得分:0)

以下是解决此问题的方法:在放大/缩小之前设置mapView.userTrackingMode = MKUserTrackingModeNone然后设置= MKUserTrackingModeFollowWithHeading。

@property (assign, nonatomic) MKUserTrackingMode lastTrackingMode;

- (IBAction)zoomInButtonPressed:(id)sender {
    self.mapView.userTrackingMode = MKUserTrackingModeNone;

    MKCoordinateRegion newRegion = MKCoordinateRegionMake(self.mapView.region.center,MKCoordinateSpanMake(self.mapView.region.span.latitudeDelta*0.5, self.mapView.region.span.longitudeDelta*0.5));
    [self.mapView setRegion:newRegion];

    self.mapView.userTrackingMode = self.lastTrackingMode;
}

- (IBAction)zoomOutButtonPressed:(id)sender {
    self.mapView.userTrackingMode = MKUserTrackingModeNone;

    // Zoom-out code goes here

    self.mapView.userTrackingMode = self.lastTrackingMode;
}