Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between MKOverlay and MKAnnotation?


I am new to MKMapView. I implemented a mapView which is looking good. But i was planning to add points or custom image as point in MapView. I can implement it with the help of MKAnnotation, but when i read MKOverlay it was mentioned that Overlays are also annotations. So whats the difference between these two??

Thanks in advance,
aby

like image 907
insomiac Avatar asked May 23 '11 18:05

insomiac


People also ask

What is Mkoverlay?

An interface for associating content with a specific map region.

What is MKAnnotation?

An interface for associating your content with a specific map location. iOS 3.0+ iPadOS 3.0+ macOS 10.9+ Mac Catalyst 13.0+ tvOS 9.2+ watchOS 2.0+


2 Answers

In a nutshell, MKAnnotation is based on a point (x,y). MKOverlay is based on an area, bounded by a rectangle.

like image 90
Rayfleck Avatar answered Sep 28 '22 00:09

Rayfleck


An MKAnnotation is simply a point on the map, often represented with a red pin icon (you'll see these if you search for a location in Apple's Maps app on iOS), whereas an MKOverlay is another layer over the map to display extra information. A good example of this could be the traffic overlay displayed on the map in US regions to indicate the current level of traffic.

You'd want to use an MKAnnotation in situations where you need to show the user a specific point on a map, but if you want to display more information to them over a larger area, go with an MKOverlay.

Apple uses an MKOverlay to display shipping routes for boats in their WWDC video on the topic (Session 127 – Customizing Maps with Overlays). That would be a good place to learn the full difference between the two, and how to use overlays correctly.

like image 22
Sam Avatar answered Sep 28 '22 00:09

Sam