如何在 iPhone 中的地图上添加放大和缩小按钮

发布于 2024-11-05 18:59:29 字数 76 浏览 0 评论 0原文

我有一张地图,我想在其中添加 2 个按钮,即。放大和缩小。单击第一个按钮时,我的地图应放大,单击第二个按钮时,我的地图应缩小。这怎么可能?

I have a map in which I want to add 2 buttons viz. zoom in and zoom out. On the click of first button my should zoom in and on the click of second button my map should zoom out. How is this possible?

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

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

发布评论

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

评论(2

千仐 2024-11-12 18:59:29

放大:

- (IBAction) zoomInClicked:(id)sender
{
    // when zoom button is clicked, zoom on a specific region
    // make region for the map to show as zoom in

    [myMapView setRegion:region animated:YES];

}

缩小:

- (IBAction)zoomOutClicked:(id)sender
{
    // make region for the map to show as zoom out
    [mapView setRegion:region animated:YES];
}

Zoom IN:

- (IBAction) zoomInClicked:(id)sender
{
    // when zoom button is clicked, zoom on a specific region
    // make region for the map to show as zoom in

    [myMapView setRegion:region animated:YES];

}

zoom Out:

- (IBAction)zoomOutClicked:(id)sender
{
    // make region for the map to show as zoom out
    [mapView setRegion:region animated:YES];
}
澜川若宁 2024-11-12 18:59:29

您无法显式设置 MKMapView。相反,您设置一个可见区域

您可以通过设置区域来做到这一点
地图的属性。一个区域是
由中心点和a定义
水平和垂直距离,
简称跨度。跨度
定义地图的大小
给定点应该是可见的并且是
以及如何设置缩放级别。
指定大跨度会导致
用户看到广阔的地理区域
并且对应于低缩放级别。
指定较小的跨度会导致
用户看到的地域范围更窄
区域并对应于更高的变焦
级别。

因此,您的两个按钮需要调整 MKCoordinateRegion 类型。增加经度Delta & latitudeDelta 将缩小,减少它们将放大。

You can't explicitly set a zoom level for the MKMapView. Instead you set a visible region

You do this by setting the region
property of the map. A region is
defined by a center point and a
horizontal and vertical distance,
referred to as the span. The span
defines how much of the map at the
given point should be visible and is
also how you set the zoom level.
Specifying a large span results in the
user seeing a wide geographical area
and corresponds to a low zoom level.
Specifying a small span results in the
user seeing a more narrow geographical
area and corresponds to a higher zoom
level.

So your two buttons need to adjust the span property of the MKCoordinateRegion type. Increasing the longitudeDelta & latitudeDelta will zoom out, decreasing them will zoom in.

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