MKMarkerAnnotationView не отображается на iPhone X - PullRequest
0 голосов
/ 29 октября 2019

На старых телефонах (iPhone 7, 8) MKMarkerAnnotationView, созданные для MKMapSnapshotter, правильно отображаются на карте. Только на iPhone X и выше они не отображаются. Я не могу сказать, в чем проблема. Вот код, который создает снимок

static func generateMap(coordinates: [CLLocationCoordinate2D], id: String){

  var annotationViews = [MKMarkerAnnotationView]()
  let startCoord = coordinates.first!
  let endCoord = coordinates.last!

  ///create mapmarker
  func createMapMarkerAnnotation(text: String, coordinates: CLLocationCoordinate2D, color: UIColor) -> MKMarkerAnnotationView{
        let annotation = MKPointAnnotation()
        annotation.coordinate = coordinates

        let annotationView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "marker")
        annotationView.glyphText = text
        annotationView.glyphTintColor = .white
        annotationView.markerTintColor = color
        annotationView.contentMode = .scaleAspectFit
        annotationView.bounds = CGRect(x: 0, y: 0, width: 40, height: 40)
        return annotationView
    }

   //CREATE MARKERS
   annotationViews.append(createMapMarkerAnnotation(text: "A", coordinates: startCoord, color: Constants.primaryGreen))
   annotationViews.append(createMapMarkerAnnotation(text: "B", coordinates: endCoord, color: Constants.primaryGreen))

  let snapshotter = MKMapSnapshotter(options: options)
    snapshotter.start { (snapshot: MKMapSnapshotter.Snapshot?, error: Error?) -> Void in
        guard error == nil, let snapshot = snapshot else { return }

        let image = snapshot.image
        UIGraphicsBeginImageContextWithOptions(image.size, true, image.scale);
        image.draw(at: CGPoint.zero) //image into context


        /// get the context for CoreGraphics
        let context = UIGraphicsGetCurrentContext()

        ///draw markers
        for view in annotationViews {
            let point: CGPoint = snapshot.point(for: view.annotation!.coordinate)
            view.drawHierarchy(in: CGRect(x: point.x - view.bounds.size.width / 2, y: point.y - view.bounds.size.height, width: view.bounds.width, height: view.bounds.height), afterScreenUpdates: true)
        }

        let finalImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()

        if let img = finalImage {
            let data: Data? = img.pngData()
            let content = data?.base64EncodedString()

            //write to db
            _ = DbTrips.shareInstance.updateTripMap(id: id, map: content!)
        }
    }
  }
}

Кто-нибудь знает, что может быть причиной того, что они не появляются на новых телефонах?

Спасибо ^. ^

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...