我用什么坐标用MKMapView手动绘制自定义路径? [英] With what coordinates do i use to manually draw a custom path with an MKMapView?

查看:132
本文介绍了我用什么坐标用MKMapView手动绘制自定义路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CLLocation2D 点, MKMapPoints MKCoordinates ,和 convertCoordinate:toPointInView:这些都以一种或另一种形式给你积分。我正在绘制自定义路线:

There are CLLocation2D points, MKMapPoints, MKCoordinates, and convertCoordinate:toPointInView: which all give you points in one form or another. I am drawing a custom route in:

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

什么是正确的绘图用点?

Whats the proper point to use for drawing?

推荐答案

    routeView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, mapView.frame.size.width, mapView.frame.size.height)];
    routeView.userInteractionEnabled = NO;
    [mapView addSubview:routeView];

-(void) updateRouteView {
CGContextRef context =  CGBitmapContextCreate(nil, 
                                                   routeView.frame.size.width, 
                                                   routeView.frame.size.height, 
                                              8, 
                                              4 * routeView.frame.size.width,
                                              CGColorSpaceCreateDeviceRGB(),
                                              kCGImageAlphaPremultipliedLast);

 CGContextSetStrokeColorWithColor(context, lineColor.CGColor);
 CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1.0);
 CGContextSetLineWidth(context, 4.0);

for(int i = 0; i < self.routes.count; i++) {
    CLLocation* location = [self.routes objectAtIndex:i];
    CGPoint point = [mapView convertCoordinate:location.coordinate toPointToView:routeView];

    if(i == 0) {
        CGContextMoveToPoint(context, point.x, routeView.frame.size.height - point.y);
    } else {
        CGContextAddLineToPoint(context, point.x, routeView.frame.size.height - point.y);
    }
}

CGContextStrokePath(context);

CGImageRef image = CGBitmapContextCreateImage(context);
UIImage* img = [UIImage imageWithCGImage:image];

routeView.image = img;
CGContextRelease(context);

}

这篇关于我用什么坐标用MKMapView手动绘制自定义路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆