本文介绍了MKMapView防止注释分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有几个注释的 MKMapView ,其中三个注释彼此非常接近.

I have a MKMapView with several annotations and 3 of them are very close to each other.

我使用了 mapView.showAnnotations(mapView.annotations,animation:false)在启动时在同一区域上显示所有注释,但由于距离太近,三个注释之一被隐藏了.

I used mapView.showAnnotations(mapView.annotations, animated: false) to display all annotations on the same region at launch but one of the 3 is hidden because it's too close.

我查看了Apple的文档,但找不到防止这种情况发生的方法,知道如何防止注释分组吗?

I looked into Apple's Documentation but couldn't find a way to prevent this from happening, any idea how to prevent annotations grouping?

(我以前从未见过,也许这是iOS 11的功能)

(I've never seen this before, maybe it's a iOS 11 feature)

推荐答案

你看到的不是聚类(你必须编写代码才能得到一个聚类,而你通常会看到一个聚类)

What you are seeing ist not clustering (you had to write code to get a cluster and you would usually see a cluster)

我的实验似乎表明...

My experiments appear to suggest...

  1. MKAnnotationViews 从地图的顶部到底部呈现.(北方在哪里都没关系.)
  2. 如果 MapKit 决定绘制重叠的 MKAnnotationViews,那么靠近底部的 MKAnnotationView 将绘制在顶部(因为它是稍后绘制的)
  3. 不仅MKAnnotationViews,在MKMArkerAnnotationViews 下呈现的标题也需要空间.这些标题的呈现受 markerView.titleVisibility 的影响.如果将 markerView.titleVisibility 设置为 .visible (而不是默认的 .adaptive ),则此标题要比 MarkerAnnotationView强,即使稍后的 MarkerAnnotationView 具有 displayPriority = .required .靠近底部的 MarkerAnnotationView 不会呈现.
  4. 即使靠近顶部的 MarkerAnnotationView 具有较低的 displayPriority,也会发生这种情况.因此, displayPriority .titleVisibility = .visible 较低的 MarkerAnnotationView 可以使 MarkerAnnotationView 靠近底部,而 displayPriority = .required 消失.
  1. MKAnnotationViews are rendered from top to bottom of the map. (It doesn't matter where north is).
  2. If MapKit decides to draw overlapping MKAnnotationViews, then the MKAnnotationView nearer to the bottom is drawn on top (because it's drawn later)
  3. Not only MKAnnotationViews, also titles rendered below MKMArkerAnnotationViews need space. The rendering of those titles is influenced by markerView.titleVisibility. If markerView.titleVisibility is set to .visible (instead of the default .adaptive), then this title is stronger than a MarkerAnnotationView that is rendered later, even if the later MarkerAnnotationView has a displayPriority = .required. The MarkerAnnotationView nearer to the bottom is not rendered.
  4. This even happens if the MarkerAnnotationView nearer to the top has a low displayPriority. So a MarkerAnnotationView with low displayPriority and .titleVisibility = .visible can make a MarkerAnnotationView nearer to the bottom with displayPriority = .required disappear.

那你应该怎么做:

  1. 对于所有相关注释,请确保 annotationView.displayPriority = .required .(这是必要的,但还不够)
  2. 不要设置 annotationView.titleVisibility = .visible ,否则标题将使在底部附近呈现的注解视图消失.而是设置 annotationView.titleVisibility = .adaptive
  1. make sure annotationView.displayPriority = .required for all relevant annotations. (This is necessary but not sufficient)
  2. Do not set annotationView.titleVisibility = .visible or the title will make annotationViews disappear that are rendered nearer the bottom. Instead set annotationView.titleVisibility = .adaptive

我认为您无法完全控制可见性.但是 annotationView.titleVisibility = .visible 的问题令我感到惊讶,您应该避免使用它,因为它隐藏注释.

I don't think you can control the visibility completely. But the problem with annotationView.titleVisibility = .visible was surprising for me and you should avoid it because it will hide annotations.

如果使用群集,群集的行为类似于(也就是)注释,其行为完全如上所述.

Clusters behave like (and are) annotations that behave exactly as described above, if clusters are used.

这篇关于MKMapView防止注释分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 12:01