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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:05:20+00:00 2026-05-23T21:05:20+00:00

I have a MapView with a toolbar button that when pushed adds overlays to

  • 0

I have a MapView with a toolbar button that when pushed adds overlays to the MapView. What I would like is for the button (IBAction) to check to see if there already are overlays on the map and if there are remove, if there are not, to add them.

My current code that adds the overlays is as follows:

- (IBAction)waterWaysAction:(id)sender 
{
NSLog(@"WaterWays pushed");

if ([mapView overlays]) {
    [mapView removeOverlays:[mapView overlays]];
    NSLog(@"WaterWays removed");
} else {
// ******* adds the overlays for the waterways **********
// inner harbor
CLLocationCoordinate2D  innerHarborPoints[13] = {
    CLLocationCoordinate2DMake(43.02313691051886, -87.90539558418189),
    CLLocationCoordinate2DMake(43.0213450482963, -87.90596442438722),
    CLLocationCoordinate2DMake(43.01721422337822, -87.90249007832719),
    CLLocationCoordinate2DMake(43.0141641230024, -87.90402523886414),
    CLLocationCoordinate2DMake(43.00858391833174, -87.8971780500095),
    CLLocationCoordinate2DMake(43.016711699807, -87.90156448365555),
    CLLocationCoordinate2DMake(43.01692320142091, -87.90093306118753),
    CLLocationCoordinate2DMake(43.02204743639911, -87.90385746629964),
    CLLocationCoordinate2DMake(43.02400128319255, -87.90186558765494),
    CLLocationCoordinate2DMake(43.02441284233703, -87.89897827382163),
    CLLocationCoordinate2DMake(43.02564995691736, -87.89925323299293),
    CLLocationCoordinate2DMake(43.02549123239004, -87.90378517804325),
    CLLocationCoordinate2DMake(43.02313691051886, -87.90539558418189)};
MKPolygon *innerHarborPolygon = [MKPolygon polygonWithCoordinates:innerHarborPoints count:13];
innerHarborPolygon.title = @"Inner Harbor";
[mapView addOverlay:innerHarborPolygon];
NSLog(@"WaterWays added");
}
}

This code works one time to add the overlay, and one time to remove it. After that (from viewing Log output) it appears as though the function (button) thinks the MapView still has overlays on it, and therefore it needs to keep removing them (even though they aren’t there anymore).

Thanks in advance for any help!

  • 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-23T21:05:20+00:00Added an answer on May 23, 2026 at 9:05 pm

    Try checking the count of the overlays array instead:

    if ([[mapView overlays] count] > 0) {
    

    Without checking the count, the overlays array can be not-nil but have no objects.

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

Sidebar

Related Questions

I have a mapView activity that has a LocationListener registered to check for a
I have a mapView to set markers on it. I would like to store
I have a MapView with Overlays like this: public class MyMapActivity extends MapActivity {
I have a simple mapview that has the following viewdidload method and didupdate to
I have a FrameLayout view which contains one (MapView-like) control and some additional buttons
I have an application that uses the mapview-overlay-manager code to draw map markers on
I have a MapView onto which I put some overlays (MKPolygon). I have to
Is there a way to have the MapView not show my current location? I'm
i have a mapview with itemizedoverlay, like in the example of mapview in androids
I have a mapview, with itemizedoverlays, exactly like in the example of Android Developer's

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.