Motion track playback: the official demo of Gaud is needed, but the moving object needs to be centered in real time
Code in Here
First and last renderings

Create CADisplayLink as timer, do not use nstimer
frameInterval frame interval, which is equivalent to how often to refresh (set to 1, which means 1 / 60 second refresh, in the example, set to 2 frames)
dpLink = CADisplayLink(target: self, selector: #selector(ViewController.update)) dpLink?.frameInterval = minframeInterval dpLink?.isPaused = false dpLink?.add(to: RunLoop.current, forMode: RunLoopMode.commonModes)
Continuously change the map center, map rotation angle and map camera angle in the update method
self.mapView.setCenter(traceCoordinates[uptateIndex+1], animated: false) self.mapView.setRotationDegree(CGFloat(yvAngle) , animated: false, duration: 1) self.mapView.setCameraDegree( CGFloat(yvAngle), animated: false, duration: 1)
Each time uptateIndex is increased by 1, temporarytraceCoordinates temporarily stores all the values before the current location, and polyline is replaced by the next one each time
if let line = self.polyline { self.mapView.remove(line) } temporarytraceCoordinates.append(traceCoordinates[uptateIndex]) polyline = MAPolyline(coordinates: &temporarytraceCoordinates, count: UInt(temporarytraceCoordinates.count))
Change line color in proxy method
func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) -> MAOverlayRenderer! { if overlay.isKind(of: MAPolyline.self) { let renderer: MAPolylineRenderer = MAPolylineRenderer.init(polyline: overlay as! MAPolyline!) renderer.lineWidth = 8.0 renderer.strokeColor = UIColor(red: 0, green: 230, blue: 239, alpha: 1) return renderer } return nil }
Poiannotationview
func mapView(_ mapView: MAMapView, viewFor annotation: MAAnnotation) -> MAAnnotationView? { if annotation.isEqual(myLocation) { let annotationIdentifier = "myLcoationIdentifier" var poiAnnotationView = mapView.dequeueReusableAnnotationView(withIdentifier: annotationIdentifier) if poiAnnotationView == nil { poiAnnotationView = MAAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier) } poiAnnotationView?.image = UIImage(named: "userHeadimage") poiAnnotationView?.imageView.layer.cornerRadius = 20 poiAnnotationView?.imageView.layer.masksToBounds = true poiAnnotationView?.imageView.backgroundColor = UIColor.white poiAnnotationView?.imageView.layer.borderColor = UIColor.white.cgColor poiAnnotationView?.imageView.layer.borderWidth = 2 poiAnnotationView!.canShowCallout = false return poiAnnotationView } return nil }
Welcome to find bug s or good suggestions issues or Email Yvente@163.com