Questions tagged [mkannotation]

An Apple protocol, for model object representing a point on a map view

An object that adopts this MKAnnotation protocol manages the data that you want to display on the map surface. It does not provide the visual representation displayed by the map. Instead, your map view either registers particular classes for annotations or the delegate provides the MKAnnotationView objects needed to display the content of your annotations. When you want to display content at a specific point on the map, add an annotation object to the map view. When the annotation’s coordinate is visible on the map, the map view asks its delegate to provide an appropriate view to display any content associated with the annotation.

There is basic MKPointAnnotation class that is useful if you do not need to add your own custom properties to an annotation.

If you do implement your own object to conform to MKAnnotation, there are a few considerations:

  1. If you want your map to respond to changes to the coordinate, title, or subtitle of the annotation object, make sure to make these conform to KVO (e.g., in Swift, declare them as dynamic).

  2. Probably obvious, but if the annotation views are configured to be draggable, you will want to make the coordinate mutable.

See also

1277 questions
8
votes
2 answers

iOS - Issue Creating Custom MKAnnotation Callout

Im having some issues styling my MKAnnotation callout bubble. Originally I had a standard callout that consisted of just a title, subtitle and leftCalloutAccessoryView. This created the following callout: This worked fine until it was decided…
ScottOBot
  • 839
  • 3
  • 16
  • 37
8
votes
6 answers

moving/updating MKOverlay on MKMapView

is there a way to update (i.e. moving around) a MKOverlay that is already added to the MKMapView. Removing a old one and adding a new one is terrible (slow). i.e i would like to trigger the background function that is calling this function when an…
user398877
  • 81
  • 1
  • 1
  • 2
8
votes
2 answers

Keep the pin (MKAnnotation) on the center when user scroll the map

I would like keep the MKAnnotaion on the centre of the screen when the user scoll the map like Careem app: So far I managed to show the pin, update the pin position but when I scroll the map, the annotation in my code initially moves and then…
Mat
  • 6,236
  • 9
  • 42
  • 55
8
votes
2 answers

iOS MapView: Add Annotation on tap, but not if existing Annotation Tapped

I have a UITapGestureRecognizer setup to add an annotation onto the map where the user clicks. The problem I'm running into is when the user taps an existing annotation to view the tooltip, the tooltip pops up, but another annotation is added to…
DoubleHolo
  • 157
  • 1
  • 10
8
votes
1 answer

must implement title when canShowCallout is YES

I'm getting this exception when trying to show the callout on my map annotation, even if the title is set. This is the init method I'm using in my MapAnnotation class: - (id)initWithTitle:(NSString *)ttl subtitle:(NSString *)sub…
Aleph72
  • 877
  • 1
  • 13
  • 40
7
votes
0 answers

Custom user picture for default User Location's callout on MKMapView

On iOS 15 (actually since iOS 14), on a MKMapView when tapping on the default User Location a callout is shown displaying kind of an 'empty' profile picture. You can see on the screenshot below the callout that appears when tapping the user…
vicegax
  • 4,709
  • 28
  • 37
7
votes
4 answers

Putting UIButton and other UIControl objects inside an MKAnnotationView and allowing user interaction

I have a custom annotation view on the map, which has a UIButton in it, but the UIButton is not responsive when pressed. I have two main problems with user interaction on the annotation view: Buttons and other controls are not responsive. I want…
jhabbott
  • 18,461
  • 9
  • 58
  • 95
7
votes
2 answers

What is the difference between MKOverlay and MKAnnotation?

I am new to MKMapView. I implemented a mapView which is looking good. But i was planning to add points or custom image as point in MapView. I can implement it with the help of MKAnnotation, but when i read MKOverlay it was mentioned that…
insomiac
  • 5,648
  • 8
  • 45
  • 73
7
votes
4 answers

Warning in Custom Map Annotations iPhone

I am using a custom map annotation class for map view in iPhone. Whenever I pop my map view from navigation bar stack I usually see some warnings in console. MapAnnotation was deallocated while key value observers were still registered with it.…
sandy
  • 2,127
  • 4
  • 28
  • 50
7
votes
1 answer

MKMapView not Clustering Annotation on zooming out map in Swift

before duplicating my questing please read the whole thing. i am using MkMapKit in my app and now I have to show people in cluster when zoom out the map, I have achieved numbering them out so far using from this answer using Apple's default…
Ahsan
  • 95
  • 1
  • 10
7
votes
1 answer

does Mapkit on IOS support dequeuing of overlays? (like it does annotations)

Does Mapkit on IOS support dequeuing of overlays? (like it does annotations). If so what is the code for achieving this? Background: With annotations I believe you can add many, leaving MapKit to instantiate views when required for them via the…
Greg
  • 34,042
  • 79
  • 253
  • 454
7
votes
1 answer

How do I show MKOverlay above MKAnnotations?

I'm trying to use an MKOverlay (specifically an MKPolyline) to show a route on the map. However, I need the route to show up above my existing pins (custom MKAnnotationViews). Is there a good way to bring the MKPolyline to the front above the pins?
bplattenburg
  • 623
  • 1
  • 8
  • 33
7
votes
4 answers

Failed to set maprect to show all annotations

I have 2 annotations to display on the mapview, but unable to set the maprect to show all of them on screen without requiring users to zoom out. I tried with showAnnotations but no luck. Anyone has been able to do this in Swift and Xcode 6.1.1?…
tala9999
  • 1,540
  • 2
  • 15
  • 25
7
votes
2 answers

Handling overlapping MKAnnotationView(s)

How can we ensure that the annotation views are placed in a specified order/ position on the map? I have a case where a single address can have multiple annotations (on top of each other). For example, Pin numbers 1, 2, 3, and 4 are placed at the…
Mustafa
  • 20,504
  • 42
  • 146
  • 209
7
votes
3 answers

UIImageView as callout's leftCalloutAccessoryView automatically shifts top-left corner

It works great on iOS 7 but UIImageView's position shifts on iO8 like images below. Also rightCalloutAccessoryView position shifts top-right corner. Can anybody help? Cheers. In iOS 7 In iOS 8 -(void)mapView:(MKMapView*)mapView…