MKMapView重叠的MKAnnotations仅允许显示两个标注 [英] MKMapView overlapping MKAnnotations only allow showing two of the callouts
问题描述
我有三个MKPointAnnotation
对象,它们以完全相同的坐标添加到MKMapView
中,并且每个对象都有唯一的标题.
I have three MKPointAnnotation
objects that are added in the exact same coordinates to an MKMapView
and they are each given a unique title.
MKPointAnnotation *a1 = [[MKPointAnnotation alloc] init];
a1.coordinate = CLLocationCoordinate2DMake(45.875684, -122.656254);
a1.title = @"Title 1";
[self.mapView addAnnotation:a1];
MKPointAnnotation *a2 = [[MKPointAnnotation alloc] init];
a2.coordinate = CLLocationCoordinate2DMake(45.875684, -122.656254);
a2.title = @"Title 2";
[self.mapView addAnnotation:a2];
MKPointAnnotation *a3 = [[MKPointAnnotation alloc] init];
a3.coordinate = CLLocationCoordinate2DMake(45.875684, -122.656254);
a3.title = @"Title 3";
[self.mapView addAnnotation:a3];
将它们添加到地图上时,通常只需点击注释,然后一次又一次点击以循环显示重叠的图钉.但是,当有两个以上注释时,即使有三个重叠,您似乎也只能循环浏览两个注释. Title 1
从不显示:
When adding them to the map, normally you can just tap the annotation, then tap again and again to cycle through the overlapped pins. However, when there are more than two, it seems you are limited to only cycling through two of the annotations, even though there are three that are overlapping. Title 1
is never shown:
对我来说,这似乎是一个MKMapView
错误,但是之前是否有其他人遇到过这种情况并找到了解决方法?
This seems like an MKMapView
bug to me, but has anyone else experienced this before and found a way around it?
推荐答案
我可以按照您的描述确认它是否有效,而且看起来确实像个bug(或者至少我找不到任何相关文档).
I can confirm this works as you describe and it does seem like a bug (or at least I couldn't find any relevant documentation).
一种解决方案(解决方法)是管理mapView可以自己处理的两个注释.然后,当用户选择(或取消选择)注释时,可以将刚刚取消选择的注释交换为第三注释.像这样:
One solution (workaround) would be to manage the two annotations that the mapView can handle by yourself. Then, when the user selects (or deselects) an annotation, you can swap the one that was just deselected to the 3rd one. Something like:
extension ViewController: MKMapViewDelegate {
func mapView(_ mapView: MKMapView, didDeselect view: MKAnnotationView) {
mapView.removeAnnotation(view.annotation!)
mapView.addAnnotation(a1)
}
}
我希望这是有道理的.祝你好运!
I hope this makes sense. Good luck!
这篇关于MKMapView重叠的MKAnnotations仅允许显示两个标注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!