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
18
votes
2 answers

MapKit (MKMapView): zPosition does not work anymore on iOS11

On iOS11 the zPosition stopped working for the annotationView.layer. Every time the map region changes. No luck with original solution: layer.zPosition = X; No luck with bringViewToFront/SendViewToBack methods Xcode 8.3/9 UPDATE (SOLUTION thanks…
Yaro
  • 1,222
  • 11
  • 15
18
votes
4 answers

How do I drop a pin with MapKit?

I would like to allow the user of my app to pick a location in the map. The native map has a "drop pin" feature where you can locate something by dropping a pin. How can I do this in MapKit?
erotsppa
  • 14,248
  • 33
  • 123
  • 181
18
votes
5 answers

Force MKMapView viewForAnnotation to update

So I have a MKMapView with all my pins added, and the colour of the pin is dependent on whether a value is set for that pin. When I first load the app, viewForAnnotation is called and the colours are set accordingly. However, when I update the pin's…
ingh.am
  • 25,981
  • 43
  • 130
  • 177
17
votes
1 answer

MKAnnotation, simple example

Is there a simple example project for MKAnnotation? I don't know what to pass at "addAnnotation", as it wants some "id". The examples at the developer site are all with arrays or parsers or so, I just need a very easy example to first…
Nareille
  • 811
  • 2
  • 11
  • 30
17
votes
2 answers

Size image pin annotation

I put the personal image instead of the traditional red pin. When I open the map to display the pin, the image cover the entire map. Is there a maximum size of the pin image or how do I integrate something in the code to fit the size standard…
Riccardo Caroli
  • 341
  • 1
  • 3
  • 12
17
votes
7 answers

set TintColor to MKAnnotationView image

I'm writing an application for iOS 7.0+ and I wanted to use new feature witch is: imageWithRenderingMode. I have a map annotation with this code: -(MKAnnotationView*)annotationView { MKAnnotationView *annotationView = [[MKAnnotationView alloc]…
Jakub
  • 13,712
  • 17
  • 82
  • 139
17
votes
2 answers

How to stop the viewForAnnotation method from overriding the default user location blue beacon in iOS

Right now I am populating a map view with annotations, and also displaying the user's current location. With the viewForAnnotation method, it overrides all annotations with the default red pin, but I want to return the views for the other…
Hudson Buddy
  • 726
  • 2
  • 9
  • 20
16
votes
1 answer

Move the annotation on Map like Uber iOS application

I am working on a project where I need to create a similar iOS application to UBER and OLA where the car is moving based on the location. I'm looking for some kind of Library which can make Cars move and take turns smoothly just like OLA. For now, I…
15
votes
6 answers

setting canShowCallOut = NO for current location annotation, iPhone

I am using custom call out (title and subtitle)for Current location icon. I tried following to disable default annotation but it does not work. - (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id ) annotation { …
chatur
  • 2,365
  • 4
  • 24
  • 38
15
votes
4 answers

Store data in MKAnnotation?

So I'm pretty new to Xcode and Objective-C. I have several ArtPiece objects with various attributes stored in an array. I then add them as MKAnnotations to the mapview. What I need to be able to do is send a reference to the array position they came…
Ryan
  • 570
  • 9
  • 25
15
votes
8 answers

How to display 2 lines of text for subtitle of MKAnnotation and change the image for the button on the right?

I am looking at Apple's MapCallouts example for map annotations and callouts (==bubbles that appear when you click on a pin). Every annotation there has coordinates, title and subtitle. I would like to display subtitle in 2 lines, i tried with: -…
DixieFlatline
  • 7,895
  • 24
  • 95
  • 147
15
votes
3 answers

iPhone: Create MKAnnotation

Can I create an MKAnnotation, or is it read only? I have coordinates, but I am not finding it easy to manually create an MKAnnotation with using setCoordinate. Ideas?
Nic Hubbard
  • 41,587
  • 63
  • 251
  • 412
15
votes
2 answers

Show annotation title automatically

I'm trying to display the annotation title automatically instead of displaying it on tap. I used the below code to display annotation and make it center on map. self.ann.setCoordinate(currentLocation2D) self.ann.title = "Title" self.ann.subtitle =…
Srujan Simha
  • 3,637
  • 8
  • 42
  • 59
14
votes
3 answers

How can I group MKAnnotations automatically regarding zoom level?

if the user zooms out on a MKMapView, i want MKAnnotations which are near to each other automatically grouped into one "group" annotation. if the user zooms back in, the "group" annotation should be split again to the unique/original…
manu
  • 967
  • 1
  • 11
  • 28
14
votes
1 answer

How to Hide MKAnnotationView Callout?

i'm trying to hide an AnnotationView without touching the pin, is the possible? Thanks! for (id currentAnnotation in self.mapView.annotations) { if ([currentAnnotation isKindOfClass:[MyAnnotation class]]) { } }
user345711
  • 181
  • 2
  • 5
1
2
3
85 86