Question

What's the difference between MKAnnotation and MKMapItem?

Which one to use when I want to display some interesting places on my map?
I have a list of objects that have latitude, longitude, title, description and photo so far and I'd like to have them on my map.

Was it helpful?

Solution

MKAnnotation is a MARKER meant for displaying stuff using a MKAnnotationView

so the procedure is:

  1. add a MKAnnotation to let the map know that there is an entry
  2. wait for the map's delegate call viewForAnnotation
  3. set up a annotationView there that is to be shown

a good tutorial (IMO) that shows this with detailed code is at: http://www.codigator.com/tutorials/mapkit-tutorial-for-ios-beginners/


MKMapItem is only for the openMapWithItem api that opens the external app!


EDIT: MKMapItem has a placemark property which is a MKAnnotation - so if that's non-nil you can add it. (note that it might be nil)

OTHER TIPS

MKAnnotation is a protocol, used to provide annotation-related information to a map view.

I think what you really meant to refer to was a MKAnnotationView, which is used to "present annotations visually in a map view".

A MKMapItem "encapsulates information about a specific point on a map. This information includes the map location and any other data that might be relevant, such as the name of a business at that location. Apps use this class to share map-related data with the Maps app."

If you want to show annotations for a specific point on your map, I suspect what you want to do is use a MKAnnotationView.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top