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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:14:10+00:00 2026-06-10T06:14:10+00:00

I’ve looked at several StackOverflow posts and Apple documentation on how to implement overlays

  • 0

I’ve looked at several StackOverflow posts and Apple documentation on how to implement overlays in MKMapView. For me, I’m interested specifically in displaying MKPolygon objects on my map. I’ve found that fundamentally, the process boils down to the following:

  • Link to MapKit and CoreLocation frameworks
  • Make an outlet to an MKMapKit object and declare view controller as delegate
  • Declare a CLLocationCoordinate2D array containing the points of a polygon and create an MKPolygon object with the class method polygonWithCoordinates:count:
  • Call addOverlay: of map and pass the newly created MKPolygon object as the parameter
  • Implement (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay

Later on, I’ll likely be having to display 20-30 polygons at a given time on the map. However, in my exploration of how to display overlays (hardcoding test examples right now, rather than reading in data from a file), I’ve found that I can get some overlays to appear, but not others. Reading the Location Awareness Programming Guide by Apple, I came across an example of a polygon overlaid above the state of Colorado. That worked. But when I tried to make a polygon that covered Kansas, I couldn’t get it to work. It seems that any polygon that I tried to make on my own (Embry-Riddle Aeronautical University polygon and Kansas polygon) won’t display, but those that I got online work perfectly. I used Google Earth to create the polygons and then exported them as KML files to get the coordinates.

Code for the implementation of my ViewController is below. Just trying to find out what I may be unintentionally doing wrong to create this problem. Thanks in advance for help.

#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>

@interface ViewController ()

@end

@implementation ViewController

@synthesize mapView;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    // Array of coordinates for polygon covering state of Colorado ... DISPLAYS PERFECTLY

    CLLocationCoordinate2D points[4];

    points[0] = CLLocationCoordinate2DMake(41.000512, -109.050116);
    points[1] = CLLocationCoordinate2DMake(36.99892, -109.045267);
    points[2] = CLLocationCoordinate2DMake(36.993076, -102.041981);
    points[3] = CLLocationCoordinate2DMake(41.002371, -102.052066);

    MKPolygon *polygon = [MKPolygon polygonWithCoordinates:points count:4];
    [mapView addOverlay:polygon];
    [polygon release];

    // Array of coordinates for polygon covering state of Kansas ... DOESN'T DISPLAY

    CLLocationCoordinate2D kansasPoints[9];

    kansasPoints[0] = CLLocationCoordinate2DMake(-102.0595440241806, 39.99774930940907);
    kansasPoints[1] = CLLocationCoordinate2DMake(-102.0424467175215, 36.99846609483674);
    kansasPoints[2] = CLLocationCoordinate2DMake(-94.62550551403953, 36.98936020770036);
    kansasPoints[3] = CLLocationCoordinate2DMake(-94.58798745384412, 39.11683771419185);
    kansasPoints[4] = CLLocationCoordinate2DMake(-94.79955391183, 39.21290793052091);
    kansasPoints[5] = CLLocationCoordinate2DMake(-95.13489191971419, 39.51613476830012);
    kansasPoints[6] = CLLocationCoordinate2DMake(-94.86553124171813, 39.78380472206268);
    kansasPoints[7] = CLLocationCoordinate2DMake(-95.02618283417986, 39.89072859904893);
    kansasPoints[8] = CLLocationCoordinate2DMake(-95.31904155494097, 39.99390420513669);

    MKPolygon *kansasPolygon = [MKPolygon polygonWithCoordinates:kansasPoints count:9];
    [mapView addOverlay:kansasPolygon];
    [kansasPolygon release];

    // Array of coordinates for polygon covering part of Daytona Beach, FL campus
    // of Embry-Riddle Aeronautical University... DOESN'T DISPLAY

    CLLocationCoordinate2D erauPoints[7];

    erauPoints[0] = CLLocationCoordinate2DMake(-81.05176, 29.18492);
    erauPoints[1] = CLLocationCoordinate2DMake(-81.04409, 29.18801);
    erauPoints[2] = CLLocationCoordinate2DMake(-81.05166, 29.19293);
    erauPoints[3] = CLLocationCoordinate2DMake(-81.05365, 29.19536);
    erauPoints[4] = CLLocationCoordinate2DMake(-81.05465, 29.19493);
    erauPoints[5] = CLLocationCoordinate2DMake(-81.05376, 29.19323);
    erauPoints[6] = CLLocationCoordinate2DMake(-81.05506, 29.19188);

    MKPolygon *erauPolygon = [MKPolygon polygonWithCoordinates:erauPoints count:7];
    [mapView addOverlay:erauPolygon];
    [erauPolygon release];

    // Array of coordinates taken from http://www.shawngrimes.me/2011/04/adding-polygon-map-overlays/
    // for commuter parking lot at Capitol College in Maryland ... DISPLAYS PERFECTLY

    CLLocationCoordinate2D commuterLotCoords[5]={
        CLLocationCoordinate2DMake(39.048019,-76.850535),
        CLLocationCoordinate2DMake(39.048027,-76.850234),
        CLLocationCoordinate2DMake(39.047407,-76.850181),
        CLLocationCoordinate2DMake(39.047407,-76.8505),
        CLLocationCoordinate2DMake(39.048019,-76.850535)
    };

    MKPolygon *commuterPoly1 = [MKPolygon polygonWithCoordinates:commuterLotCoords count:5];
    [mapView addOverlay:commuterPoly1];
    [commuterPoly1 release];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay {
    if ([overlay isKindOfClass:[MKPolygon class]]) {
        MKPolygonView *polygonView = [[[MKPolygonView alloc] initWithOverlay:overlay] autorelease];
        polygonView.fillColor = [[UIColor cyanColor] colorWithAlphaComponent:0.3f];
        polygonView.strokeColor = [UIColor redColor];
        polygonView.lineWidth = 1.0f;

        return polygonView;
    }

    return nil;
}

@end
  • 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-10T06:14:11+00:00Added an answer on June 10, 2026 at 6:14 am

    It looks like the latitude and longitude parameters of the coordinates for the polygons that don’t display are backwards.

    For example, this:

    kansasPoints[0] = CLLocationCoordinate2DMake(-102.0595440241806, 39.99774930940907);
    

    should be

    kansasPoints[0] = CLLocationCoordinate2DMake(39.99774930940907, -102.0595440241806);
    

    Also, you should not be calling release on the MKPolygon objects you are creating using polygonWithCoordinates since they will be autoreleased.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.