IOS 6 MkMapView keeps rotation when changing region

In iOS 6, I'm trying to implement the ability to change the scope of an MkMapView without changing rotation.

Basically, I need to be able to move the map to display the area (and therefore set the scale), but also I don’t want to rotate the map when I call [mapView setRegion:].

[mapView setCenterCoordinate:] works well, but does not allow you to change the zoom level.

In iOS 7, I use [mapView setCamera:]where I have a camera with a central coordinate and a specified zoom level ... I basically need this functionality in iOS 6.

Any ideas? Thanks!

+4
source share
1 answer

, [mapView setRegion:] [mapView setCamera:], .

MKCoordinateRegion currentRegion = MKCoordinateRegionMake(center, span);

double altitude = [self determineAltitudeForMapRect:MKMapRectForCoordinateRegion(currentRegion) withHeading:_heading andWithViewport:[[UIScreen mainScreen] bounds].size];

MKMapCamera *currentCamera = [MKMapCamera new];
[currentCamera setHeading:_heading];
[currentCamera setCenterCoordinate:center];
[currentCamera setAltitude:altitude];

[_mapView setCamera:currentCamera];

, [currentCamera setAltitude:], [mapView setRegion:]

fooobar.com/questions/1521093/..., , , camara 30 . , , MKMapRect:

- (double)determineAltitudeForMapRect:(MKMapRect)boundingRect withHeading:(double)heading andWithViewport:(CGSize)viewport
{
    // Get a bounding rectangle that encompasses the polygon and represents its
    // true aspect ratio based on the understanding of its heading.
    MKCoordinateRegion boundingRectRegion = MKCoordinateRegionForMapRect(boundingRect);

    // Calculate a new bounding rectangle that is corrected for the aspect ratio
    // of the viewport/camera -- this will be needed to ensure the resulting
    // altitude actually fits the polygon in view for the observer.
    CLLocationCoordinate2D upperLeftCoord = CLLocationCoordinate2DMake(boundingRectRegion.center.latitude + boundingRectRegion.span.latitudeDelta / 2, boundingRectRegion.center.longitude - boundingRectRegion.span.longitudeDelta / 2);
    CLLocationCoordinate2D upperRightCoord = CLLocationCoordinate2DMake(boundingRectRegion.center.latitude + boundingRectRegion.span.latitudeDelta / 2, boundingRectRegion.center.longitude + boundingRectRegion.span.longitudeDelta / 2);
    CLLocationCoordinate2D lowerLeftCoord = CLLocationCoordinate2DMake(boundingRectRegion.center.latitude - boundingRectRegion.span.latitudeDelta / 2, boundingRectRegion.center.longitude - boundingRectRegion.span.longitudeDelta / 2);

    CLLocationDistance hDist = MKMetersBetweenMapPoints(MKMapPointForCoordinate(upperLeftCoord), MKMapPointForCoordinate(upperRightCoord));
    CLLocationDistance vDist = MKMetersBetweenMapPoints(MKMapPointForCoordinate(upperLeftCoord), MKMapPointForCoordinate(lowerLeftCoord));

    double adjacent;

    if (boundingRect.size.height > boundingRect.size.width)
    {
        adjacent = vDist / 2;
    }
    else
    {
        adjacent = hDist / 2;
    }

    double result = adjacent / tan(DEGREES_TO_RADIANS(15));
    return result;
}
+1

Source: https://habr.com/ru/post/1524561/


All Articles