MapKit iPhone 显示缩放控件

发布于 2024-12-21 08:29:53 字数 118 浏览 0 评论 0原文

是否可以使用 MapKit 在 iPhone 中显示地图,就像我正在做的那样,在地图上显示缩放控件?

如果没有,我应该使用什么标志或方法来增加和减少缩放,这样我就可以创建只需按一下按钮即可执行此操作的方法。

Is it possible using MapKit to show a map in iPhone, like i´m doing, to display zoom controls on the map?

If not, what are the flags or methods i should use to increase and diminish the zoom, so i can created methods which will do this at the push of a button.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

等你爱我 2024-12-28 08:29:53

它没有任何内置控件。

一些建议:

  1. 您可以预定义一些跨度并将它们存储在数组中的某个位置,然后也将您的位置存储在该数组中。放大/缩小会改变位置并获取跨度。
  2. 放大采用当前跨度除以 2,缩小则乘以 2。

您可以更改 mapView 区域中的跨度。所以你必须:

  • 获取mapView的区域。
  • 获取区域的跨度。
  • 将跨度更改为您想要的值。
  • 将区域跨度设置为新跨度。
  • 将mapView的区域设置为新区域。

下面是建议 2 的一些代码:

MKCoordinateRegion region = mapView.region;
MKCoordinateSpan span;
span.latitudeDelta = region.span.latitudeDelta*2;
span.longitudeDelta = region.span.longitudeDelta*2;
region.span = span;
[mapView setRegion:region animated:TRUE];

There aren't any built-in controls for it.

A couple of suggestions:

  1. You can predefine some spans and store them in an array somewhere and then store your position in that array as well. Zooming in/out changes the position and gets the span.
  2. Zooming in takes the current span and divides by 2, zooming out multiplies by 2.

You change the span in the region of the mapView. So you have to:

  • Get the region of the mapView.
  • Get the span of the region.
  • Change the span to what you want.
  • Set the regions span to the new span.
  • Set the mapView's region to the new region.

Here's some code for suggestion 2:

MKCoordinateRegion region = mapView.region;
MKCoordinateSpan span;
span.latitudeDelta = region.span.latitudeDelta*2;
span.longitudeDelta = region.span.longitudeDelta*2;
region.span = span;
[mapView setRegion:region animated:TRUE];
陪我终i 2024-12-28 08:29:53

对于 swift 4,我使用的是:

func zoom(_ zoomin : Bool) {
    var region = mapView.region;
    var span = MKCoordinateSpan();
    span.latitudeDelta = zoomin ? region.span.latitudeDelta / 2 :  region.span.latitudeDelta * 2;
    span.longitudeDelta = zoomin ? region.span.longitudeDelta / 2 : region.span.longitudeDelta * 2;
    region.span = span;

    mapView.setRegion(region, animated: true);
}

For swift 4, this is what I use:

func zoom(_ zoomin : Bool) {
    var region = mapView.region;
    var span = MKCoordinateSpan();
    span.latitudeDelta = zoomin ? region.span.latitudeDelta / 2 :  region.span.latitudeDelta * 2;
    span.longitudeDelta = zoomin ? region.span.longitudeDelta / 2 : region.span.longitudeDelta * 2;
    region.span = span;

    mapView.setRegion(region, animated: true);
}
ゝ杯具 2024-12-28 08:29:53

我一时不记得(在 Windows 盒子上工作时)是否有一个开关来显示缩放控件。我假设您正在谈论显示缩放级别,因为默认情况下您可以捏合/展开视图以进行缩放。

如果没有显示控件的开关,那么您将需要创建一个自定义视图图层并将其放在 Mapkit 视图的顶部。然后您将需要调用不同的函数来更改缩放级别。

这些功能都记录在 Mapkit 文档中。只需在文档中心搜索 MapKit 即可。

编辑:
http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html#//apple_ref/doc/uid/TP40008205

根据文档中没有显示控件的开关,但启用缩放的属性允许您打开和关闭该功能。

因此,您可以订阅委托函数regionWillChange并使用mapView对象来获取缩放级别,然后相应地设置图形。

Off the top of my head I don't remember (at work on a windows box) if there is a switch to display the zoom controls. I assume you are talking about displaying the level of zoom, because by default you can pinch/spread the view for zoom.

If there isn't a switch to display the controls, then you will need to create a custom view layer and put it on top of the mapkit view. Then you will need to call the different functions to change the zoom level.

Those functions are all documented in the mapkit docs. Just do a search for MapKit in the documentation center.

Edit:
http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html#//apple_ref/doc/uid/TP40008205

According to the docs there isn't a switch to display the controls, but the zoom enabled property lets you turn the ability on and off.

So you can subscribe to the delegate function regionWillChange and use the mapView object to get the zoom level and then set your graphics accordingly.

無心 2024-12-28 08:29:53

我认为你不应该这样做,放大和缩小的预期方法是使用捏合手势。但是,如果您仍然想继续执行此操作,则应该将按钮放置在 MKMapView 上,然后使用这些按钮修改 MKMapView 的 region 属性

I don't think you should do that, the expected way to zoom in and out is using the pinch gestures. However if you still want to go ahead and do it, you should place yourself the buttons over the MKMapView, and then with those modify the region property of the MKMapView

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文