mapKit和注释问题

时间:2014-08-26 12:47:15

标签: xcode annotations mapkit overlays

我在这里有一个使用MapKit的应用程序,我为它绘制了一些叠加和注释。

他们确实出现了,但我必须首先移动地图,或者在绘制之前放大/缩小一点。

有什么问题吗?

1 个答案:

答案 0 :(得分:1)

只需将其调用以进行地图缩放和拟合注释: - [self zoomToFitMapAnnotations:self.mapView];

  • (void)zoomToFitMapAnnotations:(MKMapView *)aMapView { if([aMapView.annotations count] == 0)     返回;

    CLLocationCoordinate2D topLeftCoord; topLeftCoord.latitude = -90; topLeftCoord.longitude = 180;

    CLLocationCoordinate2D bottomRightCoord; bottomRightCoord.latitude = 90; bottomRightCoord.longitude = -180;

    for(PlaceMark *注释在aMapView.annotations中){     topLeftCoord.longitude = fmin(topLeftCoord.longitude,annotation.coordinate.longitude);     topLeftCoord.latitude = fmax(topLeftCoord.latitude,annotation.coordinate.latitude);

    bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, annotation.coordinate.longitude);
    bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, annotation.coordinate.latitude);
    

    }

    MKCoordinateRegion地区; region.center.latitude = topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude)* 0.5; region.center.longitude = topLeftCoord.longitude +(bottomRightCoord.longitude - topLeftCoord.longitude)* 0.5; region.span.latitudeDelta = fabs(topLeftCoord.latitude - bottomRightCoord.latitude)* 1.1; //在侧面添加一点额外空间 region.span.longitudeDelta = fabs(bottomRightCoord.longitude - topLeftCoord.longitude)* 1.1; //在侧面添加一点额外空间

    region = [aMapView regionThatFits:region]; [aMapView setRegion:region animated:YES]; }