protected override void UpdatePushpinPosition(Route e) { MKAnnotation annotation = null; if (e is Route <ResponderModel> ) { var responderRoute = e as Route <ResponderModel>; annotation = _nativeMap.Annotations .OfType <ResponderAnnotation>() .FirstOrDefault(a => a.Responder.Id == responderRoute.Element?.Id); } else if (e is Route <UserRole> ) { annotation = _nativeMap.Annotations .OfType <UserAnnotation>() .FirstOrDefault(); } if (annotation != null) { var newCoordinate = new CLLocationCoordinate2D { Latitude = e.CurrentPosition.Latitude, Longitude = e.CurrentPosition.Longitude }; annotation.SetCoordinate(newCoordinate); } }
// Animate Annotation on the map between retrieving positions private void AnimateAnnotationOnMap(MKAnnotation annotationToUpdate, Position newPosition) { var annotationToUpdateView = ViewForAnnotation(annotationToUpdate) as PinAnnotationView; if (annotationToUpdateView == null) { // crashed the app once, not sure what caused it return; } annotationToUpdateView.RefreshPinImage(); var animationOptions = UIViewAnimationOptions.CurveLinear | UIViewAnimationOptions.AllowUserInteraction | UIViewAnimationOptions.AllowAnimatedContent; Animate(5, 0, animationOptions, () => { annotationToUpdate.SetCoordinate(new CLLocationCoordinate2D(newPosition.Latitude, newPosition.Longitude)); }, () => {}); }