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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:48:07+00:00 2026-06-02T04:48:07+00:00

Is there any way to show a callout when a person touch a MKPolylineView?

  • 0

Is there any way to show a callout when a person touch a MKPolylineView?
i tried to add a UITapGestureRecognizer and in selector display a callout in some coordinate. but didnt work. any suggestions for making this?

the following is what i tried in method

 - (MKOverlayView *)mapView:(MKMapView *)mapa viewForOverlay:(id <MKOverlay>)overlay
        self.polylineView = [[MKPolylineView alloc] initWithPolyline: self.polyline];
        self.polylineView.strokeColor = [UIColor blackColor];
        self.polylineView.lineWidth = 5.0;
        self.polylineView.alpha = 0.7;
        UITapGestureRecognizer *touchOnView = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addBubble:)];
        [touchOnView setNumberOfTapsRequired:1];
        [touchOnView setNumberOfTouchesRequired:1];
        [self.polylineView addGestureRecognizer:touchOnView];
  • 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-02T04:48:09+00:00Added an answer on June 2, 2026 at 4:48 am

    Very interesting question – I’d never even thought of putting a gesture recognizer on a map overlay. With a bit of experimentation, I’ve verified it is possible to detect a tap on the MKPolylineView. Just as you found, the tap gestures don’t work on map overlays. So instead I put the tap gesture on the MKMapView rather than on the MKPolylineView. Then to handle the tap:

    - (void)handleTapGesture:(UIGestureRecognizer*)gestureRecognizer
    {
        if (measureLine != nil)
        {
            UIView* hitView = [self.polylineView hitTest:[gestureRecognizer locationInView:self.polylineView] withEvent:nil];
        }
    }
    

    hitView will be nil if your tap was outside of the MKPolylineView, or it will be self.polylineView if the tap was inside.

    However, this might not behave quite as you’d like. For horizontal and vertical lines, it works perfectly because the size of the underlying view is roughly the same size as the line. But for a 45 degree line, the underlying view has to be much larger than than the line, because it is an axis aligned bounding box (AABB). If you think about a 45 degree line, to enclose it using only horizontal and vertical lines you will end up with a large area – much larger than you’d want to detect taps in.

    e.g.

    --------
    |    / |
    |   /  |
    |  /   |
    | /    |
    |/     |
    --------
    

    But using a tap gesture or the hit test will always result in recognizing taps inside these AABBs. So regardless of where you try to attach your gesture – e.g. to the MKPolylineView as you tried, or to the MKMapView, you’ll get spurious results. The problem gets worse for longer lines – if you imagine a line going from the top right of your map view to the bottom left, the AABB that you’d need to enclose it would cover the entire area of the map view, meaning that a tap in the top left or bottom right would be interpreted as hitting the MKPolylineView.

    To solve the problem, I’d suggest the following approach:

    • Use a tap gesture recognizer on the map view
    • In your method that handles the tap:
      • convert the screen tap position to a map coordinate
      • loop through each of your polylines (unless you have only 1)
      • for each point in the polyline take the line segment that connects that point to the next point, and calculate the distance of your map coordinate away from this line. Use trigonometry to calculate this.
        • if the distance is very close to this segment, then stop checking the rest of the segments and handle whatever callouts etc you wanted to show
        • if the distance is not close, then move onto the next point and the line segment that connects it to the next but one point

    This approach is guaranteed to work regardless of the length of your polylines, or what angle they are at. There are no AABB concerns. The downside is that all of those distance calculations might be computationally expensive – so if your polylines are made up of a great number of points, or if you have a large number of polylines, then you might not be able to do all of those calculations without blocking the UI from being responsive, meaning you’d need to move it into a background thread. If you only have a handful of polylines, and/or they are made up of few points, then you’ll be fine.

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

Sidebar

Related Questions

Is there any way to show only week day with Date as: MON 03-JUL
Is there any way to show joptionpane in shutdownhook i.e I need to show
is there any way to show the driving directions in iphones MapKit? is there
Is There any way to show value and label both in sencha pie chart?
Is there any easy way to show all records from a specific mySQL row
Is there any way I can print/show images on top of each other. The
Is there any way to freeze the screen and show only one form active
Is there any way to have a default MessageBox.Show() caption? Let says I would
is there any way how to enable Eclipse to show hints for parameters of
Is there any way to configure the titanium android such that it won't show

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.