当跨度改变时,MKCooperativeregion 的中心也会改变 - iphone

发布于 2024-12-07 09:45:13 字数 1146 浏览 1 评论 0原文

我有一个名为区域的 MKCooperativeregion。我想改变这个区域的跨度而不改变它的中心。我正在使用以下方法来更改缩放。

 -(void) changeZoom
    {

     NSLog(@"before zoom span, center are   %f, %f,%f,%f", region.span.latitudeDelta, region.span.longitudeDelta, mymap.centerCoordinate.latitude, mymap.centerCoordinate.longitude);
                region.span.latitudeDelta = current_factor ;
                region.span.longitudeDelta = current_factor ;
                region.center.latitude = mymap.centerCoordinate.latitude ;
                region.center.longitude = mymap.centerCoordinate.longitude ;
                [mymap setRegion:region animated:TRUE];

                NSLog(@"after zoom span, center are   %f, %f,%f,%f", region.span.latitudeDelta, region.span.longitudeDelta, mymap.centerCoordinate.latitude, mymap.centerCoordinate.longitude);
    }

日志显示:

before zoom span, center are   0.021950, 0.021950,19.068080,72.838111
 after zoom span, center are   0.043901, 0.043901,19.068040,72.838154

此方法根据需要准确地设置了跨度。但我不希望中心坐标发生任何变化,因为当我缩小然后再缩小时,我最终会到达与起始位置不同的位置。

有没有什么方法可以在不改变中心的情况下进行放大和缩小?

感谢您提前提供的任何帮助。

I have a MKCoordinateregion called region. I want to change span of this region without changing it's center. I am using following method to change zoom.

 -(void) changeZoom
    {

     NSLog(@"before zoom span, center are   %f, %f,%f,%f", region.span.latitudeDelta, region.span.longitudeDelta, mymap.centerCoordinate.latitude, mymap.centerCoordinate.longitude);
                region.span.latitudeDelta = current_factor ;
                region.span.longitudeDelta = current_factor ;
                region.center.latitude = mymap.centerCoordinate.latitude ;
                region.center.longitude = mymap.centerCoordinate.longitude ;
                [mymap setRegion:region animated:TRUE];

                NSLog(@"after zoom span, center are   %f, %f,%f,%f", region.span.latitudeDelta, region.span.longitudeDelta, mymap.centerCoordinate.latitude, mymap.centerCoordinate.longitude);
    }

Log shows :

before zoom span, center are   0.021950, 0.021950,19.068080,72.838111
 after zoom span, center are   0.043901, 0.043901,19.068040,72.838154

This method set's span accurately as desired.But I dont want any change in the center's coordinate, Because when I zoom out and then zoom back I end up at a location different from starting location.

Is there any method so that zoom in and out are possible without any change in center?

Thanks for any help in advance.

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

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

发布评论

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

评论(2

标点 2024-12-14 09:45:13

您的前后中心坐标几乎完全相同,所以这应该不是问题。如果您确实想要完全相同相同的中心坐标,请在使用 setRegion:animated: 后立即调用 setCenterCooperative:animated: 并传递一些保存的中心坐标。

CLLocationCoordinate2D originalCenter = mymap.centerCoordinate;
// ... adjust region
[mymap setCenterCoordinate:originalCenter animated:NO];

另外,对于布尔值,您应该使用 YES 而不是 TRUE

[mymap setRegion:region animated:YES];

Your before and after center coordinates are almost exactly the same, so it shouldn't be a problem. If you really want the exact same center coordinates, call setCenterCoordinate:animated: right after you use setRegion:animated: and pass some saved center coordinates.

CLLocationCoordinate2D originalCenter = mymap.centerCoordinate;
// ... adjust region
[mymap setCenterCoordinate:originalCenter animated:NO];

Also, you should use YES instead of TRUE for booleans:

[mymap setRegion:region animated:YES];
没有伤那来痛 2024-12-14 09:45:13

您需要调整地图区域以确保纵横比适合地图视图的框架大小。

计算出具有所需中心的区域后,调整区域,

MKCoordinateRegion adjustedRegion = [mymap regionThatFits:region];
[mymap setRegion:adjustedRegion animated:TRUE];

请参阅 文档

You need to adjust the region of the map to make sure the aspect ratio fits the frame size of the map view.

Once the region with the desired center is calculated, adjust the region as,

MKCoordinateRegion adjustedRegion = [mymap regionThatFits:region];
[mymap setRegion:adjustedRegion animated:TRUE];

See docs.

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