My map has 4 or 5 points close to each other and right now using AVSpeechSynthesizer I\'ve got it so that it will say the name of the location (which is also displayed in a litt
In the didSelectAnnotationView
delegate method, the anView
parameter is the MKAnnotationView
.
That is, anView
is the view (MKAnnotationView
or MKPinAnnotationView
class) object of the annotation.
It is not the model (your MapViewAnnotation
class) object of the annotation.
To refer to the annotation model instance that the view is for, use the view's annotation
property and cast it to your class:
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)anView
{
//Get a reference to the annotation this view is for...
id<MKAnnotation> annSelected = anView.annotation;
//Before casting, make sure this annotation is our custom type
//(and not some other type like MKUserLocation)...
if ([annSelected isKindOfClass:[MapViewAnnotation class]])
{
MapViewAnnotation *mva = (MapViewAnnotation *)annSelected;
AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc]init];
AVSpeechUtterance *utterance =
[AVSpeechUtterance speechUtteranceWithString:mva.desc];
[utterance setRate:0.5];
[synthesizer speakUtterance:utterance];
}
}