Generation

generate functionThu, 25 May 2023

add a marker that the user can create with a long press. if the marker pops up a sheet should open from below with two buttons(Create marker, X). if you press x the marker should be deleted

func mapView(_ mapView: MKMapView, didLongPressAt coordinate: CLLocationCoordinate2D) { // Create a custom pin let customPin = self.mapView.addCustomAnnotation(coordinate: coordinate, title: "New Marker", subtitle: "This is a new marker") // Show an alert for adding a new pin let alert = UIAlertController(title: "New Pin", message: "This is a new pin", preferredStyle: .alert) alert.addAction(UIAlertAction(title: "X", style: .destructive, handler: { action in self.mapView.removeAnnotation(customPin) })) alert.addAction(UIAlertAction(title: "Create Marker", style: .default, handler: nil)) self.present(alert, animated: true) }

Questions about programming?Chat with your personal AI assistant