public override void DidDeselectAnnotationView (MKMapView mapView, MKAnnotationView view) { if (view.Annotation is MyAnnotation) { var myAnnotation = (MyAnnotation)view.Annotation; if (myAnnotation.AssociatedCalloutMapAnnotation != null) { mapView.RemoveAnnotation(myAnnotation.AssociatedCalloutMapAnnotation); } } }
private void RemoveAnnotations(IEnumerable <DropPin> pinsToRemove) { if (pinsToRemove == null) { return; } foreach (var dropPin in pinsToRemove) { var annotationToRemove = dropPin.PlatformMarker as MKPointAnnotation; if (annotationToRemove != null) { _nativeMap?.RemoveAnnotation(annotationToRemove); dropPin.Pin.PropertyChanged -= PinPropertyChanged; } } }
private void CreateRoute() { //Create Origin and Dest Place Marks and Map Items to use for directions //Start at Vantage Office Norwest origin_latlong = new CLLocationCoordinate2D(-33.732711, 150.9618983); //19A Cook Street Baulkham Hills 2153 destination_latlong = new CLLocationCoordinate2D(-33.762764, 150.9987214); //6 Forest Knoll Castle Hill destination_latlong = new CLLocationCoordinate2D(-33.7359772, 151.0202179); //Sydney Opera House destination_latlong = new CLLocationCoordinate2D(-33.8567844, 151.2131027); //Sydney International Airport destination_latlong = new CLLocationCoordinate2D(-33.9353852, 151.1633858); //ON Stationers Rockdale destination_latlong = new CLLocationCoordinate2D(-33.9604298, 151.1425861); orignPlaceMark = new MKPlacemark(origin_latlong); destPlaceMark = new MKPlacemark(destination_latlong); var sourceItem = new MKMapItem(orignPlaceMark); var destItem = new MKMapItem(destPlaceMark); if (start_pin != null) { map_view.RemoveAnnotation(start_pin); } if (finish_pin != null) { map_view.RemoveAnnotation(finish_pin); } start_pin = new BasicMapAnnotation(origin_latlong, "Start", "This is where we start"); map_view.AddAnnotation(start_pin); finish_pin = new BasicMapAnnotation(destination_latlong, "Finish", "You have reached your destination"); map_view.AddAnnotation(finish_pin); //Create Directions request using the source and dest items var request = new MKDirectionsRequest { Source = sourceItem, Destination = destItem, RequestsAlternateRoutes = true }; var directions = new MKDirections(request); //Hit Apple Directions server directions.CalculateDirections((response, error) => { if (error != null) { Console.WriteLine(error.LocalizedDescription); } else { var newRegion = new MKCoordinateRegion(orignPlaceMark.Coordinate, InitialZoomSpan); map_view.SetRegion(newRegion, true); Console.WriteLine($"_________________________________________________________________________________________"); Console.WriteLine($"We found {response.Routes.Length} routes:"); var i = 1; foreach (var route in response.Routes) { Console.WriteLine($" {i}) {route.Name} {route.Distance}m {route.ExpectedTravelTime}seconds"); i++; } //Add each polyline from route to map as overlay foreach (var route in response.Routes) { map_view.AddOverlay(route.Polyline); Console.WriteLine($"_________________________________________________________________________________________"); Console.WriteLine($"ROUTE INSTRUCTIONS: {route.Name} {route.Distance}m {route.ExpectedTravelTime}seconds"); if ((route.AdvisoryNotices != null) && (route.AdvisoryNotices.Length > 0)) { Console.WriteLine($" Route Notices:"); foreach (var notice in route.AdvisoryNotices) { Console.WriteLine($" {notice}"); } } Console.WriteLine($"_________________________________________________________________________________________"); foreach (var step in route.Steps) { Console.WriteLine($" {step.Distance} {step.Instructions} : {step.Polyline.Coordinate.ToString()}"); if (step.Notice != null) { Console.WriteLine($" Notice: {step.Notice} "); } } Console.WriteLine($"_________________________________________________________________________________________"); } } }); }