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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:18:48+00:00 2026-06-18T10:18:48+00:00

In my app, user draws a shape on map and using UIBeizerPath i am

  • 0

In my app, user draws a shape on map and using UIBeizerPath i am drawing that path. Then based on the coordinates of the path i am displaying the results which are only in that area. Everything works great except that now when Annotations drops on the Map view the pins looks like they are behind the path which means path looks in the front.

I am using this code to display the Annotation and path :

 -(void)clearAnnotationAndPath:(id)sender {
    [_mapView removeAnnotations:_mapView.annotations];
    path = [UIBezierPath bezierPath];
    [shapeLayer removeFromSuperlayer];
}

- (void)handleGesture:(UIPanGestureRecognizer *)gesture
{

    CGPoint location = [gesture locationInView:_pathOverlay];

    if (gesture.state == UIGestureRecognizerStateBegan)
    {
        shapeLayer = [[CAShapeLayer alloc] init];
        shapeLayer.fillColor = [[UIColor clearColor] CGColor];
        shapeLayer.strokeColor = [[UIColor greenColor] CGColor];
        shapeLayer.lineWidth = 5.0;
        //[_mapView.layer addSublayer:shapeLayer];
        [pathOverlay.layer addSublayer:shapeLayer];
        path = [UIBezierPath bezierPath];
        [path moveToPoint:location];
    }

    else if (gesture.state == UIGestureRecognizerStateChanged)
    {
        [path addLineToPoint:location];
        shapeLayer.path = [path CGPath];
    }

    else if (gesture.state == UIGestureRecognizerStateEnded)
    {
        // MKMapView *mapView = (MKMapView *)gesture.view;

        [path addLineToPoint:location];
        [path closePath];
        allStations = [RoadmapData sharedInstance].data;
        for (int i=0; i<[allStations count]; i++) {
            NSDictionary * itemNo = [allStations objectAtIndex:i];

            NSString * fullAddress = [NSString stringWithFormat:@"%@,%@,%@,%@",[itemNo objectForKey:@"address"],[itemNo objectForKey:@"city"],[itemNo objectForKey:@"state"],[itemNo objectForKey:@"zip"]];
            CLGeocoder * geoCoder = [[CLGeocoder alloc]init];
            [geoCoder geocodeAddressString:fullAddress completionHandler:^(NSArray *placemarks, NSError *error) {

                if (error) {
                    NSLog(@"Geocode failed with error: %@", error);
                    return;
                }

                if(placemarks && placemarks.count > 0)
                {
                    CLPlacemark *placemark = placemarks[0];
                    CLLocation *location = placemark.location;
                    CLLocationCoordinate2D coords = location.coordinate;
                    CGPoint loc = [_mapView convertCoordinate:coords toPointToView:_pathOverlay];
                    if ([path containsPoint:loc])
                    {
                        NSString * name = [itemNo objectForKey:@"name"];
                        stationAnn = [[LocationAnnotation alloc]initWithCoordinate:coords Title:name subTitle:@"Wells Fargo Offer" annIndex:i];
                        stationAnn.tag = i;
                        [_mapView addAnnotation:stationAnn];
                    }
                    else{
                        NSLog(@"Out of boundary");
                    }
                }
            }];
            [self turnOffGesture:gesture];
        }
    }
}

- (void)mapView:(MKMapView *)aMapView didAddAnnotationViews:(NSArray *)views{
    if (views.count > 0) {
        UIView* firstAnnotation = [views objectAtIndex:0];
        UIView* parentView = [firstAnnotation superview];
        if (_pathOverlay == nil){
            // create a transparent view to add bezier paths to
            pathOverlay = [[UIView alloc] initWithFrame: parentView.frame];
            pathOverlay.opaque = NO;
            pathOverlay.backgroundColor = [UIColor clearColor];
            [parentView addSubview:pathOverlay];
        }

        // make sure annotations stay above pathOverlay
        for (UIView* view in views) {
            [parentView bringSubviewToFront:view];
        }
    }
}

Also once i go back from this and view and come again its not even drawing the Path.

Please 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-06-18T10:18:50+00:00Added an answer on June 18, 2026 at 10:18 am

    Apparently, when you add your bezier path to the map via:

            [_mapView.layer addSublayer:shapeLayer];
    

    it is getting added above some internal layer that MKMapView uses to draw the annotations. If you take a look at this somewhat related question, you’ll see that you can implement the MKMapViewDelegate protocol, and get callbacks when new station annotations are added. When this happens, you basically inspect the view heirarchy of the newly added annotations, and insert a new, transparent UIView layer underneath them. You take care to bring all the annotations in front of this transparent UIView.

      // always remember to assign the delegate to get callbacks!
      _mapView.delegate = self;
    

    …

    #pragma mark - MKMapViewDelegate
    
    - (void)mapView:(MKMapView *)aMapView didAddAnnotationViews:(NSArray *)views{
        if (views.count > 0) {
            UIView* firstAnnotation = [views objectAtIndex:0];
            UIView* parentView = [firstAnnotation superview];
            // NOTE: could perform this initialization in viewDidLoad, too
            if (self.pathOverlay == nil){
                // create a transparent view to add bezier paths to
                pathOverlay = [[UIView alloc] initWithFrame: parentView.frame];
                pathOverlay.opaque = NO;
                pathOverlay.backgroundColor = [UIColor clearColor];
                [parentView addSubview:pathOverlay]; 
            }
    
            // make sure annotations stay above pathOverlay
            for (UIView* view in views) {
                [parentView bringSubviewToFront:view];
            }
        }
    }
    

    Then, instead of adding your shape layer to _mapView.layer, you add it to your transparent view layer, also using this new layer in the coordinate conversion:

    - (void)handleGesture:(UIPanGestureRecognizer*)gesture
    {
        CGPoint location = [gesture locationInView: self.pathOverlay];
    
        if (gesture.state == UIGestureRecognizerStateBegan)
        {
            if (!shapeLayer)
            {
                shapeLayer = [[CAShapeLayer alloc] init];
                shapeLayer.fillColor = [[UIColor clearColor] CGColor];
                shapeLayer.strokeColor = [[UIColor greenColor] CGColor];
                shapeLayer.lineWidth = 5.0;
                [pathOverlay.layer addSublayer:shapeLayer];   // <- change here !!!
            }
            self.path = [[UIBezierPath alloc] init];
            [path moveToPoint:location];
        }
        else if (gesture.state == UIGestureRecognizerStateChanged)
        {
            [path addLineToPoint:location];
            shapeLayer.path = [path CGPath];
        }
        else if (gesture.state == UIGestureRecognizerStateEnded)
        {
            /*
             * This code is the same as what you already have ...
             */
    
                 // But replace this next line with the following line ...
                 //CGPoint loc = [_mapView convertCoordinate:coords toPointToView:self];
                 CGPoint loc = [_mapView convertCoordinate:coords toPointToView: self.pathOverlay];
    
            /*
             * And again use the rest of your original code
             */            
        }
    }
    

    where I also added an ivar (and property) for the new transparent layer:

    UIView* pathOverlay;
    

    I tested this with a bogus grid of stations and got the following results:

    enter image description here

    P.S. I’d also recommend getting rid of your static variables. Just make them ivars/properties of your class.

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

Sidebar

Related Questions

In my app, the client user can draw some shape or lines, then these
I'm creating an app that uses VBO's for drawing. The app draws line segments
I am creating an app that allows the user to do some hand-drawing. The
I have a drawing app where paths are saved when the user draws and
I'm currently working on an app that allows the user to draw pixelated images
I have a web app that will draw a polyline for each user (tracks
In my app,user can select image from gallery and after that he can zoom
I'm developing web app that user can save his/her work to server. The data
I have a small app that allows the user to draw on the screen
Currently I'm developing an Android app which draws a point on the coordinates input

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.