Usando AVSpeechSynthesizer para leer una descripción de la ubicación en un Mapa
Mi mapa tiene 4 o 5 puntos cerca uno del otro y ahora mismo usando AVSpeechSynthesizer lo tengo para que diga el nombre de la ubicación (que también se muestra en una pequeña burbuja).
Quiero que todavía muestre esa burbuja, pero cuando hago clic, quiero que diga una descripción de ese lugar que habría especificado. Este es mi código en este momento:
MapViewAnnotation.h
@interface MapViewAnnotation : NSObject <MKAnnotation> {
NSString *title;
CLLocationCoordinate2D coordinate;
NSString *desc;
}
@property (nonatomic, copy) NSString *title;
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, readonly) NSString *desc;
- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d initWithDesc:(NSString *)dsc;
MapViewAnnotation.m
@implementation MapViewAnnotation
@synthesize title, coordinate, desc;
- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d initWithDesc:(NSString *)dsc {
[super init];
title = ttl;
coordinate = c2d;
desc = dsc;
return self;
MapViewController.h
@interface MapViewController : UIViewController {
MKMapView *mapView;
}
@property (nonatomic, retain) IBOutlet MKMapView *mapView;
@property (strong, nonatomic) AVSpeechSynthesizer *synthesizer;
MapViewController.m
- (void)viewDidLoad
{
// Set some coordinates for our position : Cutty Sark
CLLocationCoordinate2D location;
location.latitude = (double) 51.482997;
location.longitude = (double) -0.010072;
// Royal Observatory
CLLocationCoordinate2D twoLocation;
twoLocation.latitude = (double) 51.477805;
twoLocation.longitude = (double) -0.001430;
//Royal Naval College
CLLocationCoordinate2D threeLocation;
threeLocation.latitude = (double) 51.483344;
threeLocation.longitude = (double) -0.006799;
//Queen's House
CLLocationCoordinate2D fourLocation;
fourLocation.latitude = (double) 51.481383;
fourLocation.longitude = (double) -0.003722;
//National Maritime Museum
CLLocationCoordinate2D fiveLocation;
fiveLocation.latitude = (double) 51.481050;
fiveLocation.longitude = (double) -0.005578;
// Add Cutty Sark annotation to MapView
MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"Cutty Sark" andCoordinate:location initWithDesc:@"Description about Cutty Sark"];
[self.mapView addAnnotation:newAnnotation];
self.mapView.delegate = self;
[newAnnotation release];
// Add Royal Observatory annotation to MapView
newAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"Royal Observatory" andCoordinate:twoLocation initWithDesc:@"Description about Cutty Sark"];
[self.mapView addAnnotation:newAnnotation];
[newAnnotation release];
// Add Royal Naval College annotation to MapView
newAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"Royal Naval College" andCoordinate:threeLocation initWithDesc:@"Description about Cutty Sark"];
[self.mapView addAnnotation:newAnnotation];
[newAnnotation release];
// Add Queen's House annotation to MapView
newAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"Queen's House" andCoordinate:fourLocation initWithDesc:@"Description about Cutty Sark"];
[self.mapView addAnnotation:newAnnotation];
[newAnnotation release];
// Add National Maritime Museum annotation to MapView
newAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"National Maritime Museum" andCoordinate:fiveLocation initWithDesc:@"Description about Cutty Sark"];
[self.mapView addAnnotation:newAnnotation];
[newAnnotation release];
}
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)anView
{
AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc]init];
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:((MapViewAnnotation *)anView).desc];
[utterance setRate:0.5];
[synthesizer speakUtterance:utterance];
}
// When a map annotation point is added, zoom to it (1500 range)
- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views
{
MKAnnotationView *annotationView = [views objectAtIndex:0];
id <MKAnnotation> mp = [annotationView annotation];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate], 1500, 1500);
[mv setRegion:region animated:YES];
//[mv selectAnnotation:mp animated:YES];
}
¡Cualquier ayuda sería apreciada!
EDITAR Aquí está el NSLog: