如何在iOS中设置缩放级别?

时间:2014-11-28 06:13:03

标签: ios mkmapview cllocation mkcoordinateregion

我使用下面给出的代码在地图视图中设置区域:

    CLLocationCoordinate2D loc = (CLLocationCoordinate2D )[self geoCodeUsingAddress:searchBar.text];

    CLLocationDistance visibleDistance = 100000;
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, visibleDistance, visibleDistance);
    MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits:region];

    [self.mapView setRegion:adjustedRegion animated:YES];
    [self.mapView setCenterCoordinate:loc];
    [self.mapView setZoomEnabled:YES];

它在一个小区域显示整个地图。如何增加缩放级别?

4 个答案:

答案 0 :(得分:1)

您还可以为MapView获取span值的帮助。动画到该小区域和跨度图以缩放所需的值。

使用以下代码:

CLLocationCoordinate2D loc = (CLLocationCoordinate2D )[self geoCodeUsingAddress:searchBar.text];

[UIView animateWithDuration:1.5 animations:^{

    MKCoordinateRegion region;
    region.center.latitude = loc.latitude;
    region.center.longitude = loc.longitude;
    region.span.latitudeDelta = 0.15f;       // Decrement value to zoom
    region.span.longitudeDelta = 0.15f;      // Decrement value to zoom

    [self.mapView setRegion:region animated:YES];

} completion:^(BOOL finished) { }];

答案 1 :(得分:0)

visibleDistance更改为较小的数字。尝试直到找到你喜欢的东西。

答案 2 :(得分:0)

最后我通过删除

解决了这个问题
[self.mapView setCenterCoordinate:loc];

当我删除上述内容时,我工作得很好。

答案 3 :(得分:0)

试试这个,

CLLocationCoordinate2D loc = (CLLocationCoordinate2D )[self geoCodeUsingAddress:searchBar.text];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, visibleDistance, visibleDistance);
region.span.latitudeDelta = 0.15f;     
region.span.longitudeDelta = 0.15f; 
[self.mapView setRegion:region animated:YES];
[self.mapView setZoomEnabled:YES];