Nido Apple

Recibe ayuda de expertos

Registrate y pregunta

Es gratis y fácil

Recibe respuestas

Respuestas, votos y comentarios

Vota y selecciona respuestas

Recibe puntos, vota y da la solución

Pregunta

0voto

hidden pins makview

Hola, comenzando con mi primer desarrollo tengo un par de dudas, si es posible me gustaría me puedan resolver. Mi primera app es una típica aplicación turística de una ciudad , en la cual aparecen sitios que visitar e información de cada uno de ellos (diferentes viewcontrollers creados con storyboard), en cada uno tengo un botón que me lleva a un MapView donde aparecen todos los pins en el mapa. El problema es que cuando accedo desde un lugar determinado (viewcontroller) quiero que en el mapa solo me aparezca al pin del lugar desde que accedo, otra opción sería que aparezcan todos pero solamente la anotación del pin lugar abierta. Espero me haya explicado. Otra pregunta , si desde cada uno de los pins a través de un disclosure button quiero volver al viewcontroller del lugar, todos estos viewcontrollers estás creados con el storyboard, todos se llama igual, View Controller, para ello me tengo que crear una clase para cada uno de ellos y referenciarla con un nombre diferente¿?? Gracias. [PHP]// // ViewController2.m // Copyright (c) 2012 __MyCompanyName__. All rights reserved. // #import "ViewController2.h" #import "ViewController3.h" #import "MyAnnotation.h" @interface ViewController2 () @end @implementation ViewController2 @synthesize mapView1; - (void)viewDidLoad { [super viewDidLoad]; CLLocation *userLoc = mapView1.userLocation.location; CLLocationCoordinate2D userCoordinate = userLoc.coordinate; NSLog(@"user latitude = %f",userCoordinate.latitude); NSLog(@"user longitude = %f",userCoordinate.longitude); mapView1.delegate=self; CLLocationCoordinate2D coordinate; coordinate.latitude = 41.144300; coordinate.longitude = -8.612500; MKCoordinateRegion viewRegion =MKCoordinateRegionMakeWithDistance(coordinate, 1080, 1080); MKCoordinateRegion adjusteRegion = [mapView1 regionThatFits:viewRegion]; [mapView1 setRegion:adjusteRegion animated:YES]; NSMutableArray* annotations =[[NSMutableArray alloc] init]; CLLocationCoordinate2D theCoordinate1; theCoordinate1.latitude = 41.146300; theCoordinate1.longitude = -8.6114000; CLLocationCoordinate2D theCoordinate2; theCoordinate2.latitude = 41.147400; theCoordinate2.longitude = -8.6114000; CLLocationCoordinate2D theCoordinate3; theCoordinate3.latitude = 41.145900; theCoordinate3.longitude = -8.619900; CLLocationCoordinate2D theCoordinate4; theCoordinate4.latitude = 41.141000; theCoordinate4.longitude = -8.610900; CLLocationCoordinate2D theCoordinate5; theCoordinate5.latitude = 41.137800; theCoordinate5.longitude = -8.613900; CLLocationCoordinate2D theCoordinate6; theCoordinate6.latitude = 41.147200; theCoordinate6.longitude = -8.614700; CLLocationCoordinate2D theCoordinate7; theCoordinate7.latitude = 41.141300; theCoordinate7.longitude = -8.615100; CLLocationCoordinate2D theCoordinate8; theCoordinate8.latitude = 41.146500; theCoordinate8.longitude = -8.614000; CLLocationCoordinate2D theCoordinate9; theCoordinate9.latitude = 41.143100; theCoordinate9.longitude = -8.611400; MyAnnotation* myAnnotation1=[[MyAnnotation alloc] init]; myAnnotation1.coordinate=theCoordinate1; myAnnotation1.title=@"Plaza de la Libertad"; myAnnotation1.subtitle=@"Centro"; MyAnnotation* myAnnotation2=[[MyAnnotation alloc] init]; myAnnotation2.coordinate=theCoordinate2; myAnnotation2.title=@"Avd. de los Aliados"; myAnnotation2.subtitle=@"Ayuntamiento"; MyAnnotation* myAnnotation3=[[MyAnnotation alloc] init]; myAnnotation3.coordinate=theCoordinate3; myAnnotation3.title=@"Estación San Bento"; myAnnotation3.subtitle=@"Estación de trenes"; MyAnnotation* myAnnotation4=[[MyAnnotation alloc] init]; myAnnotation4.coordinate=theCoordinate4; myAnnotation4.title=@"Ribera"; myAnnotation4.subtitle=@"Ribera del Duero"; MyAnnotation* myAnnotation5=[[MyAnnotation alloc] init]; myAnnotation5.coordinate=theCoordinate5; myAnnotation5.title=@"Bodegas"; myAnnotation5.subtitle=@"Vino de Oporto"; MyAnnotation* myAnnotation6=[[MyAnnotation alloc] init]; myAnnotation6.coordinate=theCoordinate6; myAnnotation6.title=@"Libreria Lello er Irmao"; myAnnotation6.subtitle=@"Librería"; MyAnnotation* myAnnotation7=[[MyAnnotation alloc] init]; myAnnotation7.coordinate=theCoordinate7; myAnnotation7.title=@"Palacio de la Bolsa"; myAnnotation7.subtitle=@"Bolsa"; MyAnnotation* myAnnotation8=[[MyAnnotation alloc] init]; myAnnotation8.coordinate=theCoordinate8; myAnnotation8.title=@"Torre de los Clérigos"; myAnnotation8.subtitle=@"Iglesia"; MyAnnotation* myAnnotation9=[[MyAnnotation alloc] init]; myAnnotation9.coordinate=theCoordinate9; myAnnotation9.title=@"Catedral"; myAnnotation9.subtitle=@"Sé Catedral Oporto"; [mapView1 addAnnotation:myAnnotation1]; [mapView1 addAnnotation:myAnnotation2]; [mapView1 addAnnotation:myAnnotation3]; [mapView1 addAnnotation:myAnnotation4]; [mapView1 addAnnotation:myAnnotation5]; [mapView1 addAnnotation:myAnnotation6]; [mapView1 addAnnotation:myAnnotation7]; [mapView1 addAnnotation:myAnnotation8]; [mapView1 addAnnotation:myAnnotation9]; [annotations addObject:myAnnotation1]; [annotations addObject:myAnnotation2]; [annotations addObject:myAnnotation3]; [annotations addObject:myAnnotation4]; [annotations addObject:myAnnotation5]; [annotations addObject:myAnnotation6]; [annotations addObject:myAnnotation7]; [annotations addObject:myAnnotation8]; [annotations addObject:myAnnotation9]; NSLog(@"%d",[annotations count]); } -(IBAction) showDetails:(id) sender { ViewController3 *destino = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController3"]; [self.navigationController pushViewController:destino animated:YES]; } - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation { NSLog(@"welcome into the map view annotation"); // if it's the user location, just return nil. if ([annotation isKindOfClass:[MKUserLocation class]]) return nil; // try to dequeue an existing pin view first static NSString* AnnotationIdentifier = @"AnnotationIdentifier"; MKPinAnnotationView* pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier]; pinView.animatesDrop=YES; pinView.canShowCallout=YES; pinView.pinColor=MKPinAnnotationColorGreen; UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; [rightButton setTitle:annotation.title forState:UIControlStateNormal]; [rightButton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside]; pinView.rightCalloutAccessoryView = rightButton; return pinView; } @end [/PHP]

6 Respuestas

0voto

Peter Puntos289170
Bienvenido al sitio josean. Por favor crea una pregunta por tema, así es que para la segunda, crea un tema nuevo. Para lo del mapa [USER=5485]markfree[/USER] seguramente te puede ayudar, le avisaré para que nos eche una mano con tu duda. Saludos.

0voto

markfree Puntos4510
Ok, primero tines que hacer dos clases una con tu view y otra con un map view: en la view de cada sitio de la ciudad un ibaction asociado a un botón [PHP]-(IBAction)AnarMapa:(id)sender{ AnarMapa *mapaEjemplo = [[AnarMapa alloc] initWithNibName:@"AnarMapa" bundle:nil]; mapaEjemplo.lat = 42.10732; mapaEjemplo.lng = 1.84261; mapaEjemplo.title = @"Cal Nen"; mapaEjemplo.subTitle = @"Telefon"; [self.navigationController pushViewController:mapaEjemplo animated:YES]; }[/PHP] La classe AnarMapa tine en viewdidLoad [PHP] //Usamos los datos pasados para crear la localizacion localizacion.latitude = lat; localizacion.longitude = lng; //Zoom MKCoordinateSpan span; span.latitudeDelta=0.01; span.longitudeDelta=0.01; //Centro del mapa en las coordenadas pasadas MKCoordinateRegion region; region.span=span; region.center = localizacion; //Pasamos datos al mapa [mapView setRegion:region animated:YES]; //Añadimos pin MKPointAnnotation *pin = [[MKPointAnnotation alloc] init]; pin.coordinate = localizacion; pin.title = title; pin.subtitle = subTitle; [mapView addAnnotation:pin]; [self.mapView selectAnnotation:pin animated:FALSE]; [/PHP]

0voto

Peter Puntos289170
¿Solucionaste el problema josean?

0voto

josean Puntos480
Muchísimas gracias, Markfree y Peter y a todo MAcLatino, por cuestiones de trabajo no he podido continuar con este desarrollo, e incluso con mi aprendizaje del objetive-c. Gracias por la respuesta y perdón por el retraso. A ver si retomo de nuevo esto de los mapas. muchas gracias, de nuevo

0voto

Peter Puntos289170
De nada :)

0voto

markfree Puntos4510
Gracias a ti por pasar por aquí!

Por favor, accede o regístrate para responder a esta pregunta.

Otras Preguntas y Respuestas


Actividad Reciente

...