【问题标题】:MKUserTrackingModeFollowWithHeading, zoomMKUserTrackingModeFollowWithHeading,缩放
【发布时间】:2014-01-10 22:19:29
【问题描述】:

我使用 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 时,如何使地图保持缩放级别?

【问题讨论】:

  • 与您的问题无关,但您不需要计算 MKMapRect 来设置地图显示的内容。使用直接获取坐标和米的 MKCoordinateRegionMakeWithDistance 更容易。它返回一个 MKCoordinateRegion,您可以将其与 setRegion 一起使用,而不是调用 setVisibleMapRect。
  • 感谢您指出这一点。

标签: ios zooming mapkit tracking


【解决方案1】:

这是我解决此问题的技巧:在放大/缩小之前设置 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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-17
    • 2011-10-31
    • 2014-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-16
    相关资源
    最近更新 更多