`

ios googlemap 添加map overlay

    博客分类:
  • ios
 
阅读更多

 

 画线

 

        CLLocationCoordinate2D lats[2];
        float lat = 90-i*10;
        lats[0] = CLLocationCoordinate2DMake(lat,179);
        lats[1] = CLLocationCoordinate2DMake(lat,-179);
        MKPolyline *overlay = [MKPolylinepolylineWithCoordinates:lats count:2];
        [self.mapaddOverlay:overlay];

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay {

    MKPolylineView *polyLineView = [[[MKPolylineViewalloc] initWithOverlay:overlay] autorelease];
    CLLocationCoordinate2D coordinate = [overlay coordinate];
    if (coordinate.latitude == 0) {
        polyLineView.strokeColor = [UIColorgreenColor];
    }else{
        polyLineView.strokeColor = [UIColorblueColor];
    }
    
    if (coordinate.latitude == 0 && coordinate.longitude == 0) {
        polyLineView.strokeColor = [UIColorredColor];
    }
    polyLineView.lineWidth = 1.0;
    return polyLineView;
}

 

 自定义画字

overlay 代码

 

- (CLLocationCoordinate2D)coordinate {
    returncoordinate;                       
}


- (MKMapRect)boundingMapRect
{
    MKMapPoint upperLeft = MKMapPointForCoordinate(coordinate);
    
    CLLocationCoordinate2D lowerRightCoord = 
    CLLocationCoordinate2DMake(coordinate.latitude - 0.5,
                               coordinate.longitude + 0.5);
    
    MKMapPoint lowerRight = MKMapPointForCoordinate(lowerRightCoord);
    
    double width = lowerRight.x - upperLeft.x;
    double height = lowerRight.y - upperLeft.y;
    
    MKMapRect bounds = MKMapRectMake(upperLeft.x, upperLeft.y, width, height);
    return bounds;
}

 

 overlayView代码

 

- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context{
//    float zoom = 0.000004/zoomScale;
    MKMapRect  theMapRect = [self.overlayboundingMapRect];
    CGRect theRect = [selfrectForMapRect:theMapRect];
    
    CGContextSetAlpha(context, 0.5);
    
//    CGContextSetFillColorWithColor(context, [[UIColor redColor] CGColor]);
//    CGContextFillRect(context, theRect);


//    CGContextAddRect(context, theRect);
//    CGContextClip(context);
    
//    float w, h;
//    w = theRect.size.width;
//    h = theRect.size.height;
//    
//    CGContextSelectFont (context, // 3
//                         "Helvetica-Bold",
//                         h/10,
//                         kCGEncodingMacRoman);
//    CGContextSetCharacterSpacing (context, 10); // 4
//    CGContextSetTextDrawingMode (context, kCGTextFillStroke); // 5
//    
//    CGContextSetRGBFillColor (context, 0, 1, 0, .5); // 6
//    CGContextSetRGBStrokeColor (context, 0, 0, 1, 1); // 7
//    CGAffineTransform myTextTransform =CGAffineTransformScale(CGAffineTransformIdentity, 1.f, -1.f );
//    CGContextSetTextMatrix (context, myTextTransform); // 9
//    CGPoint xx = [self pointForMapPoint:theMapRect.origin];
//    CGContextShowTextAtPoint (context, xx.x, xx.y, "Quartz 2D", 9); 
 
    
    float w, h;
    w = theRect.size.width;
    h = theRect.size.height;
    NSString *text = [selfgenerateText];




//    CGContextSetAlpha(context, 0.5);
    CGContextSetFillColorWithColor(context, [[UIColorblackColor] CGColor]);
    
    char *commentsMsg;
    commentsMsg = (char *)[text UTF8String];
    CGContextSelectFont(context, "Helvetica-Bold", h, kCGEncodingMacRoman);// the h is the height of the text, it's key, because if it's small you can't see
    CGContextSetTextDrawingMode(context, kCGTextFill);
    
    CGAffineTransform myTextTransform =CGAffineTransformScale(CGAffineTransformIdentity, 1.f, -1.f );
    CGContextSetTextMatrix (context, myTextTransform);
    CGPoint xx = [selfpointForMapPoint:theMapRect.origin];
    CGContextShowTextAtPoint(context,xx.x,xx.y,commentsMsg, strlen(commentsMsg));// the point must convert from mappoint to cgpoint
    
}
 

 

 

 

 

 

 

 

 

 

 

asdasd

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics