使用SatelliteFlyover类型时,MKPolyline损坏了吗? [英] MKPolyline broken when using type satelliteFlyover?

查看:106
本文介绍了使用SatelliteFlyover类型时,MKPolyline损坏了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Satellite Flyover地图类型在地球上的点之间绘制一些测地线(大圆线).

I would like to draw some Geodesic Polyline(great circle line) between points on Earth using Satellite Flyover map type.

// in viewDidLoad()

mapView.mapType = .satelliteFlyover
let geodesic = MKGeodesicPolyline(coordinates: [route.airport1, route.airport2], count: 2)
self.mapView.addOverlay(geodesic)

// rendering method
    func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
        guard let polyline = overlay as? MKPolyline else {
            print("else??")
            return MKOverlayRenderer(overlay: overlay)
        }
        let renderer = MKPolylineRenderer.init(polyline: polyline)
        renderer.lineWidth = 1
        renderer.strokeColor = .systemTeal
        return renderer
    }

我可以部分创建GeodesicPolyline,但是线条不完整.

I am able to create the GeodesicPolyline partially, but the lines are not complete.

如果我处于iOS系统暗模式下,则该行显示在夜间区域"下方.

If I'm in iOS system dark mode, the line shows under the "night area".

如果禁用了暗模式,则该行显示在日区域"下.

While the line shows under the "day area" if dark mode is disabled.

我也尝试使用

self.mapView.addOverlay(geodesic, level: .aboveLabels)
self.mapView.addOverlay(geodesic, level: .aboveRoads)

,但也没有帮助.除了SatelliteFlyover或HybridFlyover以外的任何地图类型都可以正常工作.我找到了类似主题,但没有解决方案

but no help as well. Any map type other than SatelliteFlyover or HybridFlyover is working well. I found a similar topic but no solution yet.

推荐答案

我遇到了类似的问题,我发现iOS 13中的MKMultiPolylineRenderer更好地用于处理跨接MapType上的折线.您需要准备数组中的所有折线,以便可以使用所有折线:

I 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 should note that I don't use dark mode in my app, so I'm not sure if you'll see the same results I did. But this code fixed all of my broken/missing polyline problems.

这篇关于使用SatelliteFlyover类型时,MKPolyline损坏了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆