void CalculateRoute(object sender, EventArgs e) { CLLocationCoordinate2D sourceLocation = new CLLocationCoordinate2D(CustomMapView.RouteSource.Latitude, CustomMapView.RouteSource.Longitude); CLLocationCoordinate2D destinationLocation = new CLLocationCoordinate2D(CustomMapView.RouteDestination.Latitude, CustomMapView.RouteDestination.Longitude); MKPlacemark sourcePlacemark = new MKPlacemark(coordinate: sourceLocation); MKPlacemark destinationPlacemark = new MKPlacemark(coordinate: destinationLocation); sourceMapItem = new MKMapItem(sourcePlacemark); destinationMapItem = new MKMapItem(destinationPlacemark); MKPointAnnotation sourceAnnotation = new MKPointAnnotation(); //sourceAnnotation.Title = "Source"; sourceAnnotation.Coordinate = sourcePlacemark.Location.Coordinate; MKPointAnnotation destinationAnnotation = new MKPointAnnotation(); //destinationAnnotation.Title = "Destination"; destinationAnnotation.Coordinate = destinationPlacemark.Location.Coordinate; //save annotations so they can be removed later if requested annotationsList.Add(sourceAnnotation); annotationsList.Add(destinationAnnotation); NativeMapView.AddAnnotation(sourceAnnotation); NativeMapView.AddAnnotation(destinationAnnotation); CalculateRouteDetails(); }
void OnMapLongPress() { if (longPressGestureRecognizer.State != UIGestureRecognizerState.Began) { return; } CGPoint pixelLocation = longPressGestureRecognizer.LocationInView(NativeMapView); CLLocationCoordinate2D coordinate = NativeMapView.ConvertPoint(pixelLocation, NativeMapView); //add map annotation MKPointAnnotation annotation = new MKPointAnnotation(); annotation.Coordinate = coordinate; annotation.Title = string.Format("{0},{1}", coordinate.Latitude, coordinate.Longitude); NativeMapView.AddAnnotation(annotation); annotationsList.Add(annotation); }