How to use custom icons with mapKit framework?

后端 未结 2 711
隐瞒了意图╮
隐瞒了意图╮ 2020-12-16 21:42

I am using the MapKit framework to load google maps on my application and I place on map 4 \"simulated\" places like this:

- (void)viewDidLoad {

[super view         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-16 22:27

    Swift 4 and 5:

        func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
            // Check for type here, not for the Title!!!
            guard !(annotation is MKUserLocation) else {
                // we do not want to return a custom View for the User Location
                return nil
            }
            let identifier = "Identifier for this annotation"
            let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)
            annotationView.image = UIImage(named: "MyMapIcon")
            annotationView.frame = CGRect(x: 0, y: 0, width: 25, height: 25)
    
            annotationView.canShowCallout = false
            return annotationView
        }
    

提交回复
热议问题