MKMapView图像覆盖图形反转

MKMapView图像覆盖图形反转,mkmapview,cgcontext,cgimage,mkoverlay,mkmaprect,Mkmapview,Cgcontext,Cgimage,Mkoverlay,Mkmaprect,我目前正在创建一个应用程序,它需要在地图上绘制许多不同大小的覆盖图。该应用程序目前抓取2个地图点,它们代表覆盖应位于其中的边界框的角。然后我将这些转换为MKMapRect,以便在MKOverlay类中使用。覆盖图在正确的位置绘制,但图像似乎是垂直翻转的,当我尝试应用CGAffineTransformMakeRotation(180)时,我可以看出这一点,图像显示正确,但书写是反向的 如果有人能帮我弄清楚为什么要这样做,我将不胜感激,请参阅下面的代码 设置代码: // First grab

我目前正在创建一个应用程序,它需要在地图上绘制许多不同大小的覆盖图。该应用程序目前抓取2个地图点,它们代表覆盖应位于其中的边界框的角。然后我将这些转换为MKMapRect,以便在MKOverlay类中使用。覆盖图在正确的位置绘制,但图像似乎是垂直翻转的,当我尝试应用CGAffineTransformMakeRotation(180)时,我可以看出这一点,图像显示正确,但书写是反向的

如果有人能帮我弄清楚为什么要这样做,我将不胜感激,请参阅下面的代码

设置代码:

    // First grab the overlay co-ordinates
    double left = [[self.storedWildMapObject.arrayBBox objectAtIndex:0] doubleValue], bottom = [[self.storedWildMapObject.arrayBBox objectAtIndex:1] doubleValue], right = [[self.storedWildMapObject.arrayBBox objectAtIndex:2] doubleValue], top = [[self.storedWildMapObject.arrayBBox objectAtIndex:3] doubleValue];

// Store these in 2 coordinates representing top left / bot right
    CLLocationCoordinate2D upperLeftCoord =
    CLLocationCoordinate2DMake(top,left);

    CLLocationCoordinate2D lowerRightCoord =
    CLLocationCoordinate2DMake(bottom,right);

//Convert to map points
    MKMapPoint upperLeft = MKMapPointForCoordinate(upperLeftCoord);

    MKMapPoint lowerRight = MKMapPointForCoordinate(lowerRightCoord);

// Work out sizes
    double rightToLeftDiff = lowerRight.y - upperLeft.y;
    double topToBottDiff = lowerRight.x - upperLeft.x;

    MKMapRect bounds = MKMapRectMake(upperLeft.x, upperLeft.y, topToBottDiff, rightToLeftDiff);

// Add to overlay
    MKMapOverlay *mapOverlay = [[MKMapOverlay alloc] initWithMapRect:bounds andCoord:upperLeftCoord];
    [self.mapV addOverlay:mapOverlay];
//地图覆盖

- (id)initWithMapRect:(MKMapRect)rect andCoord:(CLLocationCoordinate2D)coord
{
    self = [super init];

    if (self)
    {
        self.centerPos = coord;
        self.mkMapRect = rect;
    }
    return self;
}

-(CLLocationCoordinate2D)coordinate
{
    return self.centerPos;
}

- (MKMapRect)boundingMapRect
{    
    return self.mkMapRect;
}
//地图视图

- (id)initWithOverlay:(id <MKOverlay>)overlay andImage:(UIImage *)img
{
    self = [super initWithOverlay:overlay];
    if (self)
    {
        self.image = img;
    }
    return self;
}

/** Degrees to Radian **/
#define degreesToRadians( degrees ) ( ( degrees ) / 180.0 * M_PI )

/** Radians to Degrees **/
#define radiansToDegrees( radians ) ( ( radians ) * ( 180.0 / M_PI ) )

- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)ctx
{    
    CGImageRef imageReference = self.image.CGImage;

    MKMapRect theMapRect    = [self.overlay boundingMapRect];
    CGRect theRect           = [self rectForMapRect:theMapRect];
    CGRect clipRect     = [self rectForMapRect:mapRect];

    CGContextAddRect(ctx, clipRect);
    CGContextClip(ctx);
    //CGContextRotateCTM(ctx, degreesToRadians(180.0f));

    CGContextDrawImage(ctx, theRect, imageReference);
}
下面是它的外观:


您是否验证了storedwildmapobject的坐标是否符合您所期望的顺序?

这里找到的答案似乎是用相同的mapRect正确地绘制了我的图像:


所以我现在用这个

很抱歉回复太慢,在繁忙的周末之前不要发布问题!我很确定坐标的顺序是正确的,左上角有较高的纬度和较低的纬度。当给定左上角的坐标和大小时,它确实映射在正确的位置,所以我认为这是正确的,因为宽度和高度都是正的?或者高度应该为负值,因为右下角的坐标应该具有较低的纬度?
    (lldb) p theMapRect
(MKMapRect) $17 = {
  (MKMapPoint) origin = {
    (double) x = 1.27662e+08
    (double) y = 7.86099e+07
  }
  (MKMapSize) size = {
    (double) width = 8.12378e+06
    (double) height = 1.27474e+07
  }
}