ios - map 上的折线不可见

标签 ios swift dictionary mkmapview polyline

我尝试向 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/

相关文章:

swift - 如何在 Xcode 9 中实现 PKPaymentAuthorizationViewControllerDelegate 以实现 iOS 8 向后兼容?

python - 具有 dict 输入的 Pandas "replace"根据 dict 顺序返回不同的结果(其中 dict 没有顺序)

ios - UIPopoverPresentationController 将弹出窗口显示为全屏

ios - Google Vision 是否有面部识别的 Swift 文档

ios - 如何将 NSString 追加到 NSmangedobject 中

c# - 在列表中查找具有给定属性值的对象,然后查找字典值

javascript - 确保两个单独的对象具有唯一的总键集

ios - 从数组中查找地址并将其发送到其他 View

ios - 在 swift 4.2 中交换数组值时检测到致命访问冲突

ios - tableView.moveRow 的自定义动画(位于 : to:)