MKAnnotationViews with satellite image

I have successfully set the custom image to MKAnnotationViewto replace contacts (I used the function setImage). But it only works when the type MKMapViewis "Standard." Satellite and hybrid modes always display contacts.

Does anyone have an idea to solve this strange problem?

+3
source share
4 answers

I had the same problem when I tried changing the MKPinAnnotationView image. It seems that the call to setImage is not permanent, since mapView calls setImage with the default image now and then. The solution is to subclass MKPinAnnotationView and override setImage to always set your own image:

- (void)setImage:(UIImage *)image {
    [super setImage:[UIImage imageNamed:@"MyCustomPinImage.png"]];
}
+2
source

Strange, both objects (custom MKAnnotationView and map mode) are not related to each other.

How do you replace contacts, it seems strange (setImage?), The "classic" way is to implement

- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForNnotation: (id)

and return your custom annotation view in your delegate for protocol execution MKMapViewDelegate.

0
source

yonel, setImage MKAnnotationView.image, MapViewController.

MapViewController MKMapViewDelgate:

- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation

.

, , MKnnotation . , mapView (, .. ) (.. ).

, , , , .

init customAnnotation :

- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)identifier

.

setImage , . View.

, MapType, , ( - annnotationViews ).

If you install the image in the init method, it will not be lost (since it is always installed for the instance).

Does it help?

0
source

The answer is to use MKAnnotationView instead of MKPinAnnotationView.

iOS MapKit Changing mapview type leads to changing annotation image to output?

0
source

Source: https://habr.com/ru/post/1726077/


All Articles