我尝试将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文件有错误的值......
感谢您的帮助!!!
答案 0 :(得分:0)
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);