gpt4 book ai didi

ios - Swift 中的折线叠加

转载 作者:行者123 更新时间:2023-11-28 09:38:30 24 4
gpt4 key购买 nike

我有我的 MKMapViewDelegate。此外,MapView.delegate = self

let c1 = myCLLocationCoodinate
let c2 = myCLLocationCoodinate2
var a = [c1, c2]
var polyline = MKPolyline(coordinates: &a, count: a.count)
self.MapView.addOverlay(polyline)

使用这个委托(delegate)方法:

func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! {

if overlay is MKPolyline {
var polylineRenderer = MKPolylineRenderer(overlay: overlay)
polylineRenderer.strokeColor = UIColor.whiteColor()
polylineRenderer.lineWidth = 2
return polylineRenderer
}
return nil
}

我明白了:EXC BAD ACCESS Thread 8 on

self.MapView.addOverlay(polyline)

最佳答案

我认为这里的问题在于行:

var a = [c1, c2]

这里你直接创建了数组,没有指定它的类型。

请参阅下面的引用代码来创建 Polyline 叠加层和相关的委托(delegate)方法:

let c1 = myCLLocationCoodinate
let c2 = myCLLocationCoodinate2

var points: [CLLocationCoordinate2D]
points = [c1, c2]

var geodesic = MKGeodesicPolyline(coordinates: &points[0], count: 2)
mapView.add(geodesic)

UIView.animate(withDuration: 1.5, animations: { () -> Void in
let span = MKCoordinateSpanMake(20, 20)
let region1 = MKCoordinateRegion(center: c1, span: span)
mapView.setRegion(region1, animated: true)
})

渲染叠加层的委托(delegate)方法:

func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! {

if overlay is MKPolyline {
var polylineRenderer = MKPolylineRenderer(overlay: overlay)
polylineRenderer.strokeColor = UIColor.whiteColor()
polylineRenderer.lineWidth = 2
return polylineRenderer
}
return nil
}

关于ios - Swift 中的折线叠加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27305871/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com