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 6868693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:27:56+00:00 2026-05-27T03:27:56+00:00

I am using mapkit on iPhone with iOS 4. I am using a custom

  • 0

I am using mapkit on iPhone with iOS 4.
I am using a custom overlay and a custom overlay view, to draw shapes on the map.
At the moment, shapes are just rectangles, but I am planning something more sophisticated. This is why I am not using the MKPolygon overlay type.
This is the code for my overlay view drawing method:

-(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context
{
    // Clip context to bounding rectangle
    MKMapRect boundingMapRect = [[self overlay] boundingMapRect];
    CGRect boundingRect = [self rectForMapRect:boundingMapRect];
    CGContextAddRect(context, boundingRect);
    CGContextClip(context);

    // Define shape
    CGRect shapeRect = CGRectMake(0.5f, 0.5f, boundingRect.size.width - 1.0f, boundingRect.size.height - 1.0f);

    // Fill
    CGContextSetRGBFillColor(context, 0.5f, 0.5f, 0.5f, 0.5f);
    CGContextFillRect(context, shapeRect);

    // Stroke
    CGContextSetRGBStrokeColor(context, 0, 0, 0, 0.75f);
    CGContextSetLineWidth(context, 1.0f);
    CGContextStrokeRect(context, shapeRect);
}

The problem is that rectangles get correctly filled (so it appears their bounding rect is correctly set), but they don’t get stroked.
Can anyone help?
Thanks!

  • 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-05-27T03:27:57+00:00Added an answer on May 27, 2026 at 3:27 am

    As reported in some previous comments, the problem is with line width. More generally, all drawing is automatically scaled to follow the map zooming, so if you want some of your drawing metrics to be zoom-independent, you have to divide it by zoomScale.

    Here is the new code, that works correctly on my iPhone 4:

    -(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context
    {
        // Clip context to bounding rectangle
        MKMapRect boundingMapRect = [[self overlay] boundingMapRect];
        CGRect boundingRect = [self rectForMapRect:boundingMapRect];
        CGContextAddRect(context, boundingRect);
        CGContextClip(context);
    
        // Define shape
        CGRect shapeRect = CGRectInset(boundingRect, 2.0f / zoomScale, 2.0f / zoomScale);
    
        // Fill
        CGContextSetRGBFillColor(context, 0.5f, 0.5f, 0.5f, 0.5f);
        CGContextFillRect(context, shapeRect);
    
        // Stroke
        CGContextSetRGBStrokeColor(context, 0, 0, 0, 0.75f);
        CGContextSetLineWidth(context, 4.0f / zoomScale);
        CGContextStrokeRect(context, shapeRect);
    }
    

    I will also report the code I am using in the overlay to calculate and return the bounding rectangle, because I think it can help:

    -(MKMapRect)boundingMapRect
    {
        // Overlay bounds
        CLLocationCoordinate2D topLeftcoordinate = <the top-left coordinate of overlay>;
        CLLocationCoordinate2D bottomRightCoordinate = <the bottom-right coordinate of overlay>;
    
        // Convert them to map points
        MKMapPoint topLeftPoint = MKMapPointForCoordinate(topLeftcoordinate);
        MKMapPoint bottomRightPoint = MKMapPointForCoordinate(bottomRightCoordinate);
    
        // Calculate map rect
        return MKMapRectMake(topLeftPoint.x, topLeftPoint.y, bottomRightPoint.x - topLeftPoint.x, topLeftPoint.y - bottomRightPoint.y);
    }
    

    Thank you all for your comments and suggestions.

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

Sidebar

Related Questions

I'd like to overlay a custom map using MapKit. I've currently implemented the TileMap
In my iphone application, I'm using MapKit with MKMapView and custom MKAnnotationView. The problem
Developing iphone application using makkit framework. I have got the map view integrated in
Is it possible using MapKit to show a map in iPhone, like i´m doing,
I am using the MapKit for the iPhone and have it setup to get
Having follow the tutorial at http://mithin.in/2009/06/22/using-iphone-sdk-mapkit-framework-a-tutorial/ to integrate the MapKit into my application. However,
i want to integrate maps using map kit in iphone, and i am successful
I am using map kit and showing customized annotation view. One is carImage and
In my iPhone app I'm using MapKit to show the user where he is,
Here is my scenario: I am building a location finder using the iPhone mapkit.

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.