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

MKMapKit error: MKMapPointsPerMeterAtLatitude EXC_BAD_ACCESS

What this error means? MKMapPointsPerMeterAtLatitude EXC_BAD_ACCESS It happens, when I am trying add new MKAnnotation to the MKMapView.
petesalt
  • 356
  • 3
  • 20
-1
votes
1 answer

Pass data in swift from one class to another

I have an app where a user takes a photo and he creates the annotation on the map with this photo, the photo has to be transferred to ImageAnnotation class and than a pin must be created on the map import UIKit import MapKit import…
-1
votes
1 answer

Size of custom MKPointAnnotation

I've a problem with the size of a custom MKAnnotationView. I set a custom image but when the zoom of the MKMapView change the size of the annotation don't. I lost the default behaviour of the annotation like disappear in term of the zoom, resizing…
-1
votes
1 answer

why annotationView cannot be selected when moving animation

When the animation is executing , i try to click the moving annotationView ,but cannnot be selected, the mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) hasn't been called func addMoveAnimation() { guard let ano = annotation…
chunxi
  • 19
  • 2
-1
votes
1 answer

Count Annotations on MapView in Swift

After completing a loop that places annotations on a map from an array, I want to count the number of annotations. My code as follows: let anCount = self.mapView.annotations?.count if (anCount > 1) { //do something } gives…
user1904273
  • 4,562
  • 11
  • 45
  • 96
-1
votes
1 answer

Deleting wrong displayed annotation when deleting selected MKAnnotation from map SWIFT 4.1

I have an userAlertAnnotationArray: [MKAnnotations] that gets entries from data retrieved from Firebase. The deleting part is working perfectly with posts in Firebase and entries in the array, but it fails when deleting the selected MKAnnotation…
Vincenzo
  • 5,304
  • 5
  • 38
  • 96
-1
votes
1 answer

For Loop not running in ViewDidLoad - everything else is

The download restaurant function returns 2, so it's not an issue of an empty array. However, as I try to take each value in the array and put it through my for loop to add an annotation to the map, nothing happens. No print statement, no…
jonpeter
  • 599
  • 8
  • 28
-1
votes
1 answer

Swift - How can I trigger a segue when MKAnnotation button is pressed?

Swift-Newbie question: I have two view controllers: My home VC which uses MapKit and a second 'MapDetailViewController' to display additional information. On the home VC, I have added a point of interest with an annotation to display the name of…
Kris
  • 11
  • 1
-1
votes
1 answer

Change the location coordinates, change the pin and redraw the routes on a map

I have created a single view application using the storyboard. I placed the mkMapView on a ViewController and embed it in navigation controller.so that the program is showing the routes between two pin that are source and destination coordinates in…
user4277177
-1
votes
1 answer

Won't Show Custom Pin Image

Im trying to make Custom Pin Images to show up in my mapView and it's presenting the regular red pin instead of my Custom Image. What am i doing wrong? ViewFor Annotation: func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) ->…
Newbie Questions
  • 463
  • 1
  • 11
  • 31
-1
votes
1 answer

MKAnotation - cannot assign value of typ x to type MKAnnotation

I have a map with annotations working fine. I want to have a segmentedcontrol to change the annotations. this code annotations = getMapAnnotations() // Add mappoints to Map mapInfView.addAnnotations(annotations ) works in the ViewDidLoad but I'm…
cpmac
  • 69
  • 8
-1
votes
1 answer

how do i draw a path from my current location to the annotation pin i have set in my mapView?

I have created a mapView(sorry i named my outlet as mapKit instead of mapView). I fetched my current location and i have manually set an annotation pin to a location. Now what i need is as soon as i click on the annotation pin(Please exactly on the…
Thejus
  • 169
  • 12
-1
votes
2 answers

how to get permission for map and zoom to user location?

I tired to get indexpath of my custom annotation , I use this code for get my indexpath NSUInteger index =[mapView.annotations indexOfObject:view.annotation]; its not really working because in my map, i got right lat and lang but not get the true…
-1
votes
1 answer

Swift - Make reverseGeocoderLocation run first

I have following code: func addAnnotation(gesture: UIGestureRecognizer){ //touch point var touchPoint = gesture.locationInView(self.UImapMK) var location = UImapMK.convertPoint(touchPoint, toCoordinateFromView: self.UImapMK) var…
-1
votes
1 answer

Extract Map Annotations from Plist swift

Firstly, I have found loads covering this issue on StackOverflow but it is all ObjectiveC and not Swift. Can anyone provide a link, or share some code to explain how to extract annotations information from a plist? My Plist is...
metheone
  • 15
  • 3