AnnotationPoint überlagert callout

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • AnnotationPoint überlagert callout

    Hallo,

    kann mir jemand helfen? Mein Map View Controller hat die Aufgabe, eine location in einem callout zu zeigen. Beim draufklicken kommt man auf die map app. Klapp auch. Jetzt ist aber auf dem callout immer noch die annotation vom Typ MKPointAnnotation überlagert. D.h. ich mochte die rote Annotation löschen, und nur den callout angezeigt haben. Wie mache ich das ohne mein Projekt zu zerschießen?

    Quellcode

    1. class MapViewController: UIViewController, MKMapViewDelegate
    2. {
    3. //outlet variable is used for establishing a connection with the map view in the storyboard
    4. @IBOutlet var mapView: MKMapView!
    5. // @IBOutlet var segmentedControl: UISegmentedControl!
    6. var spot = Spot()
    7. let locationManager = CLLocationManager()
    8. var currentPlacemark:CLPlacemark?// it is used to save the selected spot
    9. var currentTransportType = MKDirectionsTransportType.automobile
    10. var currentRoute: MKRoute?// store the current route
    11. override func viewDidLoad()
    12. {
    13. super.viewDidLoad()
    14. // self.navigationItem.backBarButtonItem?.title = " "
    15. navigationItem.backBarButtonItem = UIBarButtonItem(title:"", style: .plain, target: nil, action:nil)
    16. // we want to show the users location
    17. mapView.delegate = self//important
    18. mapView.showsUserLocation = true
    19. //request for a user's authorization for lacation services
    20. locationManager.requestWhenInUseAuthorization()
    21. let status = CLLocationManager.authorizationStatus()
    22. if status == CLAuthorizationStatus.authorizedWhenInUse
    23. {
    24. mapView.showsUserLocation = true
    25. }
    26. let geoCoder = CLGeocoder()
    27. geoCoder.geocodeAddressString(spot.location,
    28. completionHandler:
    29. {
    30. placemarks, error in
    31. if let error = error
    32. {
    33. print(error)
    34. return
    35. }
    36. if let placemarks = placemarks
    37. {
    38. //get the first placemark
    39. let placemark = placemarks[0]
    40. // value of current Placemark
    41. self.currentPlacemark = placemark
    42. // // add annotation
    43. let annotation = MKPointAnnotation()// here is the issue
    44. annotation.title = self.spot.name
    45. annotation.subtitle = self.spot.type
    46. if let location = placemark.location
    47. {
    48. annotation.coordinate = location.coordinate
    49. self.mapView.addAnnotations([annotation])
    50. //display the annotation
    51. self.mapView.showAnnotations([annotation],animated:true)
    52. self.mapView.selectAnnotation(annotation, animated: true)
    53. }
    54. }
    55. })
    56. // save.openInMaps(launch)
    57. if #available(iOS 9.0, *) {
    58. mapView.showsCompass = true
    59. mapView.showsTraffic = true
    60. mapView.showsScale = true
    61. }
    62. }
    63. func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    64. // guard let annotation = annotation as? Spot else {return nil}
    65. let identifier = "Marker"
    66. var view: MKMarkerAnnotationView
    67. if let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
    68. as? MKMarkerAnnotationView {
    69. dequeuedView.annotation = annotation as! MKAnnotation
    70. view = dequeuedView
    71. } else {
    72. view = MKMarkerAnnotationView(annotation: annotation as! MKAnnotation, reuseIdentifier: identifier)
    73. view.canShowCallout = true
    74. view.calloutOffset = CGPoint(x:-5,y:5)
    75. view.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
    76. }
    77. return view
    78. }
    79. func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
    80. print("Annotation is tapped")
    81. var geocoder = CLGeocoder()
    82. geocoder.geocodeAddressString(spot.location) {
    83. placemarks, error in
    84. var placemark = placemarks?.first
    85. let regionDistance:CLLocationDistance = 1000;
    86. let lat: CLLocationDegrees = (placemark?.location?.coordinate.latitude)!
    87. let lon: CLLocationDegrees = (placemark?.location?.coordinate.longitude)!
    88. let coordinates = CLLocationCoordinate2DMake(lat, lon)
    89. let regionSpan = MKCoordinateRegion(center: coordinates, latitudinalMeters: regionDistance, longitudinalMeters: regionDistance)
    90. let options = [MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center), MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span)]
    91. placemark = MKPlacemark(coordinate: coordinates)
    92. let mapItem = MKMapItem(placemark:placemark as! MKPlacemark)
    93. mapItem.name = self.spot.location
    94. mapItem.openInMaps(launchOptions: options)
    95. }
    96. }
    97. override func didReceiveMemoryWarning()
    98. {
    99. super.didReceiveMemoryWarning()
    100. // Dispose of any resources hat can be recreated.
    101. }
    102. }
    Alles anzeigen