-1

I'm using MapKit in my project and everything works perfectly.

However, I've noticed an issue, annotations may appear over one another, if the longitude and latitude are the same which is understandable. However, as a result, this renders some annotations unaccessible to the user to tap and read more information, as they overlap one another, so my question is - is there a way I can ensure that even if the long & lat are the exact same annotations can be spaced out or avoid the overlapping?

I've even zoomed in and they're directly above one another.

SwiftUser
  • 555
  • 6
  • 17
  • No, there is no built-in mechanism to implement this as you have outlined. The typical solution is to do clustering, and if you select a cluster annotation view that represents multiple, overlapping annotations, show some additional UI that shows the user a list of locations and lets them select one from that list. See standard Maps app for an example. – Rob Oct 12 '20 at 19:13

1 Answers1

1

Annotations cannot be spaced out if they are indeed the same location. Your options are:

  • You can cluster multiple proximate annotations into a single annotation by giving the annotation views a clusteringIdentifier

  • You can hide annotations if they would otherwise overlap another annotation by giving the annotations views a lowered displayPriority

But you cannot make them appear in a false location, no.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • With `clusteringIdentifier` would I still be able to tap and view the details of each annotation? – SwiftUser Oct 12 '20 at 18:34
  • 1
    The clustered annotation view is itself an annotation view. — Look, instead of coming back to me, what about _learning_ about this? Try it for yourself: https://developer.apple.com/documentation/mapkit/mkannotationview/decluttering_a_map_with_mapkit_annotation_clustering – matt Oct 12 '20 at 18:38