1

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

 -(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

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

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

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

4

2 回答 2

1

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

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

此外,您应该使用YES而不是TRUE布尔值:

[mymap setRegion:region animated:YES];
于 2011-10-01T12:59:56.797 回答
0

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

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

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

请参阅文档

于 2011-10-01T06:10:13.083 回答