繁体   English   中英

LatLonBox到CLLocationCoordinate2D

[英]LatLonBox to CLLocationCoordinate2D

我尝试将LatLonBox坐标转换为CLLocationCoordinate2D。 但是我认为某处是一个错误,因为图像不适合..

 <LatLonBox>
  <north>2.254403</north>
  <south>-55.256903</south>
  <east>161.994477</east>
  <west>98.003023</west>
  <rotation>0</rotation>
</LatLonBox>

这是我转换LatLonBox坐标的函数。

** --- MapOverlay:NSObject --- **

-(id)initWithNorth:(double)north south:(double)south west:(double)west east:(double)east imageStr:(NSString*)imageStr{

    self = [super init];
    if (self) {
        imageString = imageStr;

        CLLocationCoordinate2D lowerLeftCoordinate = CLLocationCoordinate2DMake(south, west); // south, west
        CLLocationCoordinate2D upperRightCoordinate = CLLocationCoordinate2DMake(north, east); //north,east


        baseCoordinate = lowerLeftCoordinate;

        MKMapPoint lowerLeft = MKMapPointForCoordinate(lowerLeftCoordinate);
        MKMapPoint upperRight = MKMapPointForCoordinate(upperRightCoordinate);

        mapRect = MKMapRectMake(lowerLeft.x, upperRight.y, upperRight.x - lowerLeft.x, lowerLeft.y - upperRight.y);
    }

    return self;
}

** --- MapOverlayView:MKOverlayView --- **

- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)ctx
{

    CGImageRef imageReference = image.CGImage;

    //Loading and setting the image
    MKMapRect theMapRect    =  [self.overlay boundingMapRect];
    CGRect theRect           = [self rectForMapRect:theMapRect];


    // We need to flip and reposition the image here
    CGContextScaleCTM(ctx, 1.0, -1.0);
    CGContextTranslateCTM(ctx, 0.0, -theRect.size.height);

    //drawing the image to the context
    CGContextDrawImage(ctx, theRect, imageReference);

}

** ---我的地图--- **

//Adding the overlay to the map
MapOverlay * mapOverlay = [[MapOverlay alloc] initWithNorth:2.254403
                                                      south:-55.256903
                                                       west:161.994477
                                                       east:98.003023
                                                   imageStr:@"EarthquakeHazard.png"];
[self addOverlay:mapOverlay];

关键是,如果我改变北值。 (-2.2544 ..)图像向下移动。 然后它不应该上升到??


好吧,该功能可以正常工作。 我的.kml文件值错误...

谢谢你的帮助!!!

mapRect = MKMapRectMake(lowerLeft.x, upperRight.y, upperRight.x - lowerLeft.x, lowerLeft.y - upperRight.y);

应该是

mapRect = MKMapRectMake(lowerLeft.x, upperRight.y, upperRight.x - lowerLeft.x, upperRight.y - lowerLeft.y);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM