void DrawStepForIndex(int index, bool needZoom = true)
        {
            if (currentDirectionAnnotation != null && index == currentStepIndex)
            {
                return;
            }

            currentStepIndex = index;

//			mapView.RemoveAnnotations (listStepAnnotation.ToArray ());
//			listStepAnnotation.Clear ();

            RouteItem item = ViewModel.Routes [index];
            CLLocationCoordinate2D coordinate = new CLLocationCoordinate2D(item.Lat, item.Long);

//			StepAnnotation annotation = new StepAnnotation ();
//
//			annotation.SetCoordinate (coordinate);
//			mapView.AddAnnotation (annotation);
//			listStepAnnotation.Add (annotation);

            if (needZoom)
            {
                MKCoordinateRegion region = MKCoordinateRegion.FromDistance(coordinate, 400, 400);
                mapView.SetRegion(region, true);
//				mapView.SetCenterCoordinate (coordinate, true);
            }

            if (currentDirectionAnnotation != null)
            {
                mapView.RemoveAnnotation(currentDirectionAnnotation);
            }
            currentDirectionAnnotation = null;

            DirectionAnnotation nextDirectionAnnotation = new DirectionAnnotation();

            nextDirectionAnnotation.SetCoordinate(coordinate);

            if (currentStepIndex < ViewModel.Routes.Count - 1)
            {
                RouteItem nextItem = ViewModel.Routes [index + 1];

                CLLocationCoordinate2D nextCoordinate = new CLLocationCoordinate2D(nextItem.Lat, nextItem.Long);

                nextDirectionAnnotation.CurAngle = CalcBearing(coordinate, nextCoordinate).ToRad();
            }
            else
            {
                if (desCoordinate.IsValid())
                {
                    nextDirectionAnnotation.SetCoordinate(desCoordinate);

                    nextDirectionAnnotation.CurAngle = CalcBearing(coordinate, desCoordinate).ToRad();
                }
            }

            mapView.AddAnnotation(nextDirectionAnnotation);
            currentDirectionAnnotation = nextDirectionAnnotation;
        }
        public MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            if (annotation is MKUserLocation)
            {
                return(null);
            }

            if (annotation is StepAnnotation)
            {
                var annotationView = mapView.DequeueReusableAnnotation("StepAnnotation") as MKPinAnnotationView;
                if (annotationView == null)
                {
                    annotationView = new MKPinAnnotationView(annotation, "StepAnnotation");
                }
                annotationView.Annotation = annotation;
                annotationView.PinColor   = MKPinAnnotationColor.Green;
                return(annotationView);
            }

            if (annotation is DestinationAnnotation)
            {
                var annotationView = mapView.DequeueReusableAnnotation("DesinationAnnotation") as MKPinAnnotationView;
                if (annotationView == null)
                {
                    annotationView = new MKPinAnnotationView(annotation, "DesinationAnnotation");
                }
                annotationView.Annotation = annotation;
                annotationView.PinColor   = MKPinAnnotationColor.Purple;
                return(annotationView);
            }

            if (annotation is DirectionAnnotation)
            {
                DirectionAnnotation directionAnnotation = annotation as DirectionAnnotation;
                var annotationView = mapView.DequeueReusableAnnotation("DirectionAnnotation") as MKAnnotationView;
                if (annotationView == null)
                {
                    annotationView       = new MKAnnotationView(annotation, "DirectionAnnotation");
                    annotationView.Image = UIImage.FromFile("small_blue_icon_navigate.png");
                }

                annotationView.Annotation = annotation;

                CGAffineTransform transform = CGAffineTransform.MakeRotation((nfloat)directionAnnotation.CurAngle + lastAngle);
                annotationView.Transform = transform;

                return(annotationView);
            }

            return(null);
        }
        public void EndNavigation()
        {
            mapView.RemoveOverlays(mapView.Overlays);
            mapView.RemoveAnnotations(mapView.Annotations);
            currentDirectionAnnotation = null;

            if (destinationAnnotation != null)
            {
                mapView.AddAnnotation(destinationAnnotation);
                destinationAnnotation = null;
            }

            mapView.SetRegion(overviewRegion, true);
        }
 public void ChangeNavigationMode()
 {
     if (!ViewModel.IsNavigating)
     {
         // overview
         if (currentDirectionAnnotation != null)
         {
             mapView.RemoveAnnotation(currentDirectionAnnotation);
         }
         currentDirectionAnnotation = null;
         mapView.SetRegion(overviewRegion, true);
     }
     else
     {
         //resume
         DrawStepForIndex(currentStepIndex, true);
     }
 }