gpt4 book ai didi

ios - map 上的折线不可见

转载 作者:可可西里 更新时间:2023-11-01 01:52:23 25 4
gpt4 key购买 nike

我尝试向 map 添加折线,但它不可见。

locationManager.startUpdatingLocation()
guard let locValue: CLLocationCoordinate2D =
locationManager.location?.coordinate else { return }
Map.setCenter(locValue, animated: true)

if !locations.contains(where: {$0.latitude == locValue.latitude && $0.longitude == locValue.longitude}) {
locations.append(locValue)
NSLog("Add: %f %f -> Count: %i", locValue.latitude, locValue.longitude, locations.count)

let polyline = MKPolyline(coordinates: &locations, count: locations.count)
Map.addOverlay(mapView(Map, rendererFor: polyline).overlay)
}

“我的” map View 功能:

func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
let polyLine = overlay
let polyLineRenderer = MKPolylineRenderer(overlay: polyLine)
polyLineRenderer.strokeColor = UIColor.red
polyLineRenderer.lineWidth = 5.0
return polyLineRenderer
}

最佳答案

你可以试试

self.map.delegate = self

let polyline = MKPolyline(coordinates:locations, count: locations.count) 
self.map.addOverlay(routeLine)

关于ios - map 上的折线不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53912695/

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