:d
我正在尝试删除mapView中的叠加层
我试试这个:
myLocation是mapView
let overlays = myLocation.overlays
myLocation.removeOverlays(overlays)
和此:
var polyline : MKPolyline = MKPolyline()
myLocation.removeOverlay(polyline)
但两者都不适合我:C
任何人都可以帮助我吗?
答案 0 :(得分:2)
试试mapView.removeOverlays(mapView.overlays)
。您还可以标记特定叠加层并循环显示它们以删除特定叠加层。
答案 1 :(得分:1)
//添加叠加:
let polyline: MKPolyline = MKPolyline()
polyline.tag = 100 //any number that you will use to identify this overlay
mapView.addOverlay(polyline)
//删除叠加层:
for overlay in mapView.overlays {
if (overlay.tag == 100) {
mapView.removeOverlay(overlay)
}
}
答案 2 :(得分:0)
尝试一下!
self.mapView.overlays.forEach {
if ($0 is MKPolyline) {
self.mapView.removeOverlay($0)
}
}