Slight increase on MKCoordinateRegion?

I scale MKMapView to fit the bounding area of ​​the contacts collection, however, when the contacts are displayed, I noticed that the increase could ideally be a little tougher. My suggested solution for this was to make the region's deltas a little smaller:

// SMALL ZOOM
region.span.latitudeDelta = (upper.latitude - lower.latitude) * 0.9;
region.span.longitudeDelta = (upper.longitude - lower.longitude) * 0.9;

However, I noticed that the fine-tuning does not seem to translate into a slight increase in magnification, is there some form of zoom binding? Really small values ​​work, like really big ones, but just adjusting the region size by a few percent does not seem to work with a view that almost always jumps / approaches distant and cuts off my contacts.

EDIT:

Quick tests showing the results of various scaling factors in a region:

 //                                                             SCALE FACTOR
 //                                                                  V
 region.span.latitudeDelta  =   (upper.latitude - lower.latitude) * 0.9;
 region.span.longitudeDelta = (upper.longitude - lower.longitude) * 0.9;

Here are the results:

  • x0.5 area is too small, some annotations from the screen
  • x0.6 Same as using 1.0
  • x0.7 Same as using 1.0
  • x0.8 Same as using 1.0
  • x0.9 Same as using 1.0
  • x1.0 Original fit
  • x1.1 area is too large, annotations are too small on the screen

My point is that very small adjustments (e.g. 0.6 to 0.9) do not seem to make any difference.

+5
source share
2 answers

. , mapview , . "" . , "" . , , , . regionThatFits: , .

, , ( ) 2- ( ), . "" .

, iOS , Google Maps. , .

, , - iOS 4, , , . 3, . , iOS 4.

region.span.longitudeDelta = (maxCoord.longitude - minCoord.longitude) / 3.0;
region.span.latitudeDelta = (maxCoord.latitude - minCoord.latitude) / 3.0;

, * 0.9, .

, , , , regionThatFits:, , mapview . , iOS 4.0. , MKCoordinateRegion regionThatFits: . , , , Apple.

+6

. , , MKMapView , , . "" , ( 1.1).

MapKit.

- (void)zoomToFitMapAnnotations:(MKMapView *)mapView
{
    if ([mapView.annotations count] == 0)
        return;

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

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

    for (MapAnnotation *annotation in mapView.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;
    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; // Add a little extra space on the sides
    region.span.longitudeDelta = fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.1; // Add a little extra space on the sides

    region = [mapView regionThatFits:region];
    [mapView setRegion:region animated:YES];
}
+4

All Articles