Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7933779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:25:49+00:00 2026-06-03T21:25:49+00:00

I have a map custom view that inherit from MKOverlayPathView. I need this custom

  • 0

I have a map custom view that inherit from MKOverlayPathView. I need this custom view to display circle, line and text.

I already managed to draw circle and line using path drawing CGPathAddArc and CGPathAddLineToPoint functions.

However, I still need to add text.

I tried to add text using

 [text drawAtPoint:centerPoint withFont:font];

but I got invalid context error.

any idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T21:25:51+00:00Added an answer on June 3, 2026 at 9:25 pm

    With MKOverlayPathView, I think the easiest way to add text is to override drawMapRect:zoomScale:inContext: and put the path and text drawing there (and do nothing in or don’t implement createPath).

    But if you’re going to use drawMapRect anyway, you might want to just switch to subclassing a plain MKOverlayView instead of MKOverlayPathView.

    With an MKOverlayView, override the drawMapRect:zoomScale:inContext: method and draw the circle using CGContextAddArc (or CGContextAddEllipseInRect or CGPathAddArc).

    You can draw the text using drawAtPoint in this method which will have the required context.

    For example:

    -(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context
    {
        //calculate CG values from circle coordinate and radius...
        CLLocationCoordinate2D center = circle_overlay_center_coordinate_here;
    
        CGPoint centerPoint = 
            [self pointForMapPoint:MKMapPointForCoordinate(center)];
    
        CGFloat radius = MKMapPointsPerMeterAtLatitude(center.latitude) * 
                             circle_overlay_radius_here;
    
        CGFloat roadWidth = MKRoadWidthAtZoomScale(zoomScale);
    
        //draw the circle...
        CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
        CGContextSetFillColorWithColor(context, [[UIColor blueColor] colorWithAlphaComponent:0.2].CGColor);
        CGContextSetLineWidth(context, roadWidth);
        CGContextAddArc(context, centerPoint.x, centerPoint.y, radius, 0, 2 * M_PI, true);
        CGContextDrawPath(context, kCGPathFillStroke);
    
        //draw the text...
        NSString *text = @"Hello";
        UIGraphicsPushContext(context);
        [[UIColor redColor] set];
        [text drawAtPoint:centerPoint 
                 withFont:[UIFont systemFontOfSize:(5.0 * roadWidth)]];
        UIGraphicsPopContext();
    }
    

    In relation to a comment in another answer…

    When the center coordinate or radius (or whatever) of the associated MKOverlay changes, you can make the MKOverlayView “move” by calling setNeedsDisplayInMapRect: on it (instead of removing and adding the overlay again). (When using a MKOverlayPathView, you can call invalidatePath instead.)

    When calling setNeedsDisplayInMapRect:, you can pass the boundingMapRect of the overlay for the map rect parameter.

    In the LocationReminders sample app from WWDC 2010, the overlay view uses KVO to observe changes to the associated MKOverlay and makes itself move whenever it detects a change to the circle’s properties but you could monitor the changes in other ways and call setNeedsDisplayInMapRect: explicitly from outside the overlay view.


    (In a comment on another answer I did mention using MKOverlayPathView and that is how the LocationReminders app implements a moving circle overlay view. But I should have mentioned how you can also use MKOverlayView to draw a circle. Sorry about that.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have a map view that loads from an image that I
I have custom map image with specific height and width. i need to map
I have a Map that uses a Set for the key type, like this:
I currently have a simple list view adapter that holds two rows of text.
I have some map view controller and I have a custom annotation. Custom annotation
I currently have a map view that is populated with several objects following the
I have a map view with annotations, and these annotations display a callout. When
I have a large non-map image that I want to allow people to view
For an app I'm building, I have a custom old map effect PNG that
I have a custom annotation view on the map, which has a UIButton in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.