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
7
votes
4 answers

How do I change the frame position for a custom MKAnnotationView?

I am trying to make a custom annotation view by subclassing MKAnnotationView and overriding the drawRect method. I want the view to be drawn offset from the annotation's position, somewhat like MKPinAnnotationView does it, so that the point of the…
andrei
  • 2,053
  • 3
  • 17
  • 16
7
votes
1 answer

MKAnnotation and setCoordinate:

I have a custom class that conforms to the MKAnnotation protocol. An instance of this class is held by a viewController, along with an object of type MKMapView, called _mapView. I've set the viewController to be _mapView's delegate. In the custom…
Nick
  • 628
  • 6
  • 21
6
votes
2 answers

MKMapView annotations changing/losing order?

I have a map view with annotations, and these annotations display a callout. When the callout's disclosure detail button is clicked, it segues into a new view. My MKAnnotations are a custom class that implements . Let's call that…
Seth Nelson
  • 2,598
  • 4
  • 22
  • 29
6
votes
1 answer

Custom callout view for MKAnnotation?

The standard callout, a black bubble, is nice, but can this be customized? For instance I would like to make a white bubble version.
cannyboy
  • 24,180
  • 40
  • 146
  • 252
6
votes
1 answer

How to display multiple callouts from MKAnnotationView?

I like implement sth. like this. I have two annotations with callouts, but MKMapView allows only one to be selected at the same time. [mapView selectAnnotation:self.firstAnnotation animated:FALSE]; [mapView selectAnnotation:self.secondAnnotation…
6
votes
2 answers

How to properly put 2000+ Custom Annotations on SwiftUI Map():View to keep lag to minimum

I was curious about what is the best practice when you need to have a bunch of custom annotations on Map in SwiftUI. This is my first real IOS project, so I'm a little rough around the edges. Currently, I have 2400 annotations, they are buttons with…
jPax101
  • 61
  • 4
6
votes
1 answer

Draw MKPointAnnotation with title in MKSnapshot image

I'm trying to draw an annotation exactly as in a 'live' MapView, but then in a MKSnapshot. Why an MKSnapshot > because I want to have non-interactive MapViews in a UITableView and using images is more efficient. I can get a pin to be drawn (though…
6
votes
3 answers

didAddAnnotationViews not working on MKMapView

I've been playing around with the MKMapView and trying get my head around how the MKMapViewDelegate system works. So far I have no luck in getting the didAddAnnotationViews to get called when the current location marker is added. I have set my app…
BenBtg
  • 836
  • 1
  • 9
  • 22
6
votes
2 answers

Remove annotations from map and replace with updated annotations (qTree)

I am currently working on adding cluster annotations to my map view. Everything is working fine with the exception of a couple of things. First of all, I need to refresh the annotations on the map when the user leaves and returns to the view. At the…
user3746428
  • 11,047
  • 20
  • 81
  • 137
6
votes
4 answers

Unable to conform MKAnnotation protocol in Swift

When I try to conform MKAnnotation protocol it throw error my class does not conform to protocol MKAnnotation. I am using the following code import MapKit import Foundation class MyAnnotation: NSObject, MKAnnotation { } The same thing is…
Aditya
  • 333
  • 3
  • 9
6
votes
2 answers

iPhone - MapKit - Searching locations and moving annotations

I want to make an app that partially mimics some of the behavior the standard map application has. This has proven difficult. First of all, I don't understand how you make annotations movable. How exactly do you do this? Second: how do you search…
quano
  • 18,812
  • 25
  • 97
  • 108
6
votes
2 answers

Clean solution to know which MKAnnotation has been tapped?

Ok, so you typically have some object X you want to be annotated inside a MKMapView. You do this way: DDAnnotation *annotation = [[DDAnnotation alloc] initWithCoordinate: poi.geoLocation.coordinate title: @"My Annotation"]; [_mapView addAnnotation:…
Stefano Verna
  • 642
  • 9
  • 23
6
votes
1 answer

MKAnnotationView disappearing on swipe and double-tap zoom

I have subclassed MKAnnotationView to create an annotation that basically draws a circle around a point on a map view through override of drawRect. The circle draws fine in the following situations (in the simulator): On initial load of the map…
Steve N
  • 2,667
  • 3
  • 30
  • 37
6
votes
1 answer

iOS7: MKAnnotation centerOffset?

So the centerOffset property of MKAnnotation does not seem to work on iOS7 for working with custom annotation images... Below are images taken in iOS6 (working) and in iOS7 (not working). Do you guys know what's causing this issue? Is there any fix…
Zoltán Matók
  • 3,923
  • 2
  • 33
  • 64
6
votes
3 answers

MKMapView clustering if too many Map Pins nearby

I'm wondering if any of you knows a method (library, category, etc.) to cluster iOS MapAnnotations if there are many of them at the same location (e.g. 4 pieces in about 10m). It doesn't matter to zoom in because they are still overlapping. I've…
kimar
  • 191
  • 2
  • 8