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
9
votes
1 answer

Current Location with custom annotation, call-out and blue accuracy circle

After 2 hours of googling I couldn't find an answer so this is my last shot. I would like to use a custom annotation for the user current location on a mkmapview. But I also want to have the blue accuracy circle around it. Can this be done? If…
Christian Loncle
  • 1,584
  • 3
  • 20
  • 30
9
votes
2 answers

Swift - Custom MKAnnotationView, set label title

I am trying to customise the MKAnnotationView for my mapView callout bubbles. I am fine with setting the annotation title when the annotation is created, and also customising the MKAnnotationView to add labels or images e.t.c (in the…
TimWhiting
  • 2,405
  • 5
  • 21
  • 41
9
votes
4 answers

Issue with overlapping annotations (MKAnnotationView) on map

In my iphone application, I'm using MapKit with MKMapView and custom MKAnnotationView. The problem is when annotations overlap on map (in my app, annotations are photos and those photos may overlap) and when you tap on the annotation that appears on…
9
votes
4 answers

Is it possible to call animatesDrop in a MKAnnotationView rather than MKPinAnnotationView?

do you know that MKPinAnnotationView has a method "animatesDrop" to animate a pin annotation from the top to point on the map with a shadow? OK, is it possible do this with a custom image??
Mat
  • 7,613
  • 4
  • 40
  • 56
9
votes
3 answers

How to count number and which annotations shown on MapView, when zooming?

I need to count number of annotations when i zooming mapView, and get array with which are shown on map, and then, i need to reload my Table and show list of only which shown on map. How can i get number and array with annotation?
Nubaslon
  • 741
  • 2
  • 11
  • 27
9
votes
6 answers

MKAnnotationView and tap detection

I have a MKMapView. I added a UITapGestureRecognizer with a single tap. I now want to add a MKAnnotationView to the map. I can tap the annotation and mapView:mapView didSelectAnnotationView:view fires (which is where I'll add additional logic to…
Padin215
  • 7,444
  • 13
  • 65
  • 103
9
votes
7 answers

Display MKMapViewAnnotations within a map view's visible rect

I'm displaying an MKMapView inside a Path-style parallax table view header. To create the effect, the mapView bounds is larger than the area visible to the user. I need to set the map view region such that all the map's annotations are contained…
user2393462435
  • 2,652
  • 5
  • 37
  • 45
9
votes
1 answer

Positioning a custom MKAnnotationView

I create a custom MKAnnoationView as follows: - (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id )annotation { static NSString* AnnotationIdentifier = @"AnnotationIdentifier"; MKAnnotationView*…
Darren
  • 10,091
  • 18
  • 65
  • 108
9
votes
2 answers

What spatial indexing algorithm should I use?

I want to implement some king of spatial indexing data structure for my MKAnnotations. Currently it's horribly slow when I try to filter them based on distance criteria ( 3-4k of locations, currently extremely slow with a simple double for ...…
Templar
  • 1,694
  • 1
  • 14
  • 32
8
votes
2 answers

Hide MKUserLocation when MKMapView showsUserLocation == YES

After setting mapView.showsUserLocation to true, is it possible to receive location updates without showing the MKUserLocation bubble? Returning nil in mapView:viewForAnnotation: simply shows the bubble, and returning any other kind of annotation…
eric.mitchell
  • 8,817
  • 12
  • 54
  • 92
8
votes
3 answers

How do you let a user add a pin to a map and get the coordinates in SwiftUI?

I have a map in a view that is centered on Chicago. I want the user to be able to place a pin/annotation on the map and then retrieve those coordinates. The map loads Chicago fine but I can't get the annotation code to work. I can't seem to find an…
8
votes
1 answer

Custom MKAnnotation Image goes back to default when I attempt to drag

I've got a bunch of MKAnnotations that don't need dragging. I set this by [pin setDraggable:NO]. I'm having an issue when I touch the annotation and (accidentally) drag off an annotation, it instantly looses it's custom image and changes back to…
capikaw
  • 12,232
  • 2
  • 43
  • 46
8
votes
4 answers

Cannot find protocol declaration MKAnnotation

The code is: @interface RouteMapAnnotation : NSObject { CLLocationCoordinate2D coordinate; NSString* title; NSString* subtitle; } @property (nonatomic, readonly) CLLocationCoordinate2D…
aherlambang
  • 14,290
  • 50
  • 150
  • 253
8
votes
2 answers

Adding Multiple Annotations to Map But All Show Some of Same Data

UPDATE 2: Here is the existing code within maps, but it is like the annotations get all out of order with the pins. One time a pin will be green, the next time I run it, the same pin is red. Where is the disconnect coming from? -(void)…
user717452
  • 33
  • 14
  • 73
  • 149
8
votes
1 answer

custom MKAnnotation not moving when coordinate set

I've got a custom MKAnnotation set up class Location: NSObject, MKAnnotation { var id: Int var title: String? var name: String var coordinate: CLLocationCoordinate2D { didSet{ didChangeValueForKey("coordinate") …
Jason G
  • 2,395
  • 2
  • 24
  • 34