使用MKUserTrackingBarButtonItem时如何指定缩放级别? [英] How do I specify the zoom level when using an MKUserTrackingBarButtonItem?

查看:106
本文介绍了使用MKUserTrackingBarButtonItem时如何指定缩放级别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MKUserTrackingBarButtonItem按钮来允许用户自动跟踪他们在地图上的位置.问题在于,当他们点击此按钮时,其缩放得太远了.我希望它以指定的缩放级别(即跨度)开始.我该如何实现?

I am using a MKUserTrackingBarButtonItem button to allow the user to automatically track their location on a map. The problem is that when they tap this button, it is zoomed too far out. I want it to start at a specified zoom level (i.e. span). How can I achieve this?

当用户点击按钮以更改为MKUserTrackingModeFollow时,似乎使用的是用户上次手动更改的缩放级别(即使用地图上的手势).尝试通过setRegionsetVisibleMapRect指定不同的缩放级别不会影响将模式更改为MKUserTrackingModeFollow时将使用的缩放级别.

When the user taps the button to change to MKUserTrackingModeFollow, it seems to use the same zoom level that the user last manually changed to (i.e. using gestures on the map). Attempting to specify a different zoom level via setRegion or setVisibleMapRect does not affect what zoom level will be used when the mode is changed to MKUserTrackingModeFollow.

尝试使用override mapView:didChangeUserTrackingMode:设置区域会导致模式更改回MKUserTrackingModeNone.示例:

Attempting to override mapView:didChangeUserTrackingMode: to set the region causes the mode to be changed back to MKUserTrackingModeNone. Example:

- (void)mapView:(MKMapView *)mapView didChangeUserTrackingMode:(MKUserTrackingMode)mode animated:(BOOL)animated {
    if (mode == MKUserTrackingModeFollow) {
        CLLocationCoordinate2D center = mapView.userLocation.location.coordinate;
        MKCoordinateSpan span = MKCoordinateSpanMake(0.002306, 0.001717);
        [mapView setRegion:MKCoordinateRegionMake(center, span) animated:YES];
        // [mapView setUserTrackingMode:MKUserTrackingModeFollow animated:NO];
    }
}

如果我尝试在设置区域后立即重置模式,则在用户静止不动时可以正常工作,但是在用户移动时可以缩小.

If I attempt to reset the mode immediately after setting the region, it works fine if the user is stationary, but zooms back out if the user is moving.

最简单的解决方案是,如果有一种方法可以通过将其span值发送给MKUserTraking来简单地指定诸如缩放级别之类的内容.但是,由于似乎不存在,该怎么办?

The simplest solution would be if there was a way to simply specify something like a zoom level for MKUserTraking by sending it my span value. However, since that doesn't seem to exist, what else can I do?

推荐答案

我遇到了同样的问题,并使用了不同的方法来解决它.您可以为此使用MapCamera函数而不是该按钮.

I had the same issue and used a different approach to fix it. You can use the MapCamera function for this instead of that button.

在每个新位置上执行以下操作:

On each new location do this:

 MKMapCamera *newCamera = [MKMapCamera cameraLookingAtCenterCoordinate:[newLocation coordinate]
 fromEyeCoordinate:[oldLocation coordinate]
 eyeAltitude:2000];

 [mapView setCamera:newCamera animated:TRUE];

然后用eyeAltitude玩.

And play with the eyeAltitude.

如果用户手动放大或缩小,则可以从mapview.camera.海拔高度中读取高度值.当用户手动使用地图时,海拔高度也不会更新相机.

If the user manually zooms in or out you can read the altitude value from mapview.camera.altitude also don't update the camera when the user is manually using the map.

这篇关于使用MKUserTrackingBarButtonItem时如何指定缩放级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆