2012-05-17 55 views
6

Tôi muốn biết nếu có cách nào để có zoom động khi tôi đặt trong chế độ xem bản đồ của tôi chấm màu xanh lam (vị trí của tôi) và một ghim khác ... khi tôi tải mapview I muốn hiển thị hai điểm này trong cùng một khung hình ... có thể không? cảm ơnIOS: phóng to bản đồ cho hai chú thích điểm

Trả lời

8

Có, điều đó là có thể. Sau khi thêm chú thích thứ hai. mẫu mã này sẽ làm việc cho bất kỳ số lượng chú thích:

MKMapRect zoomRect = MKMapRectNull; 
NSArray *annotations = [mapView annotations]; 
for (MKAnnotation *annotation in annotations) { 

    MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate); 
    MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0); 
    if (MKMapRectIsNull(zoomRect)) { 
     zoomRect = pointRect; 
    } else { 
     zoomRect = MKMapRectUnion(zoomRect, pointRect); 
    } 

} 

[mapView setVisibleMapRect:zoomRect animated:YES]; 
+1

nó tốt hơn ..... http: //stackoverflow.com/questions/4680649/zooming-mkmapview-to-fit-annotation-pins – CrazyDev

+1

Cảm ơn bạn , thực sự hữu ích, tôi chỉ cần sửa đổi loại biến "chú thích" _ từ ** 'MKAnnotation' ** thành **' MKPointAnnotation' ** và hoạt động;)! – IgniteCoders

Các vấn đề liên quan