问题描述
我想在MapKit的mapView上方显示几个MKPolylines
.问题是将地图类型设置为.satelliteFlyover
时,我的折线会消失.如果我更改为仅使用.satellite
,则它们是可见的.
I want to show a few MKPolylines
on top of MapKit's mapView. The problem is when setting the map type to .satelliteFlyover
my polylines will disappear. If I change to just using .satellite
they're visible.
mapView.type = .satelliteFlyover
mapView.addOverlay(polyline)
推荐答案
遇到了类似的问题,我发现iOS 13中的MKMultiPolylineRenderer更好地用于处理跨接MapType上的折线.您需要准备数组中的所有折线,以便可以使用所有折线:
had a similar problem, and I found that the MKMultiPolylineRenderer in iOS 13 is much better for handling polylines on a flyover MapType. You need to do prepare all of your polylines in an array so you have ALL polylines available:
var multiArray = [MKPolyline]()
// CREATE ALL OF YOUR POLYLINES AND APPEND THEM TO multiArray
view.addOverlay(MKMultiPolyline(multiArray))
然后,您需要创建一段代码来处理func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer
中的MKMultiPolylines.我从字面上复制了我的MKPolyline部分,只是将所有引用从MKPolyline
更改为MKMultiPolyline
.
Then you need to create a section of code to handle MKMultiPolylines in func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer
. I literally copied my MKPolyline section and just changed any reference from MKPolyline
to MKMultiPolyline
.
如果您无法将目标更改为iOS 13,该怎么办?两种跨接地图类型在iOS 13之前都表现出类似的情况.我也是,我只是无法解决跨接图类型.
IDK what to do if you can't change your target to iOS 13. Both flyover map types exhibit a similar situation before iOS 13. I'm also having problems with MKCircle that I just can't fix on the flyover map types.
这篇关于当类型为SatelliteFlyover时在MapView顶部显示MKPolyline?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!