我是新开发者。我希望通过按钮跟踪用户移动,例如当点击按钮MapKit显示叠加或用户移动时。 我有这段代码:
var mapOverlay: MKTileOverlay!
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
if overlay is MKPolyline {
let polylineRenderer = MKPolylineRenderer(overlay: overlay)
polylineRenderer.strokeColor = UIColor.red
polylineRenderer.lineWidth = 3
return polylineRenderer
}
return MKOverlayRenderer()
}
@IBAction func start(_ sender: Any) {
let annotation = MKPointAnnotation()
annotation.coordinate = mapView.userLocation.coordinate
annotation.subtitle = "Start"
self.mapView.addAnnotation(annotation)
}