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

Problema con del delegado LocationManager

Hola escribo por que quiero hacer una app que con el delegado de : – (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation En newlocation tendira que recibir la posición del gps del iphone. No se por que no funciona… Lo pruevo con la app en el iphone con Ios5 Version xcode 4.1 en el macbook pro i 4.2 en imac ( en ninguno funciona) simulador 4.3 i 5 ( tampoco) He aplicado el hack: @implementation CLLocationManager (TemporaryHack) - (void)hackLocationFix { CLLocation *location = [[CLLocation alloc] initWithLatitude:lat longitude:longi]; [[self delegate] locationManager:self didUpdateToLocation:location fromLocation:nil]; } - (void)startUpdatingLocation { [self performSelector:@selector(hackLocationFix) withObject:nil afterDelay:0.1]; } @end y sigue sin funcionar. En el .m: @implementation PosicioGPSViewController @synthesize mapa,manager; - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } #pragma mark - View lifecycle // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { self.manager = [[CLLocationManager alloc]init]; manager.delegate = self; manager.desiredAccuracy = kCLLocationAccuracyBest; manager.distanceFilter = 5; [manager startUpdatingLocation]; [mapa setShowsUserLocation:YES]; [super viewDidLoad]; } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{ latidutstri = [[NSString alloc]initWithFormat:@"%g",newLocation.coordinate.latitude]; longitudStri = [[NSString alloc]initWithFormat:@"%g",newLocation.coordinate.longitude]; MKCoordinateRegion regio; regio.center.latitude = newLocation.coordinate.latitude; regio.center.longitude = newLocation.coordinate.longitude; regio.span.latitudeDelta = 0.5; regio.span.longitudeDelta = 0.5 ; [mapa setRegion:regio animated:YES]; NSLog(@"lati:%@ lon:%@",latidutstri, longitudStri); lat = newLocation.coordinate.latitude; longi = newLocation.coordinate.longitude; } - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{ UIAlertView * alerta =[[UIAlertView alloc] initWithTitle:@"Error al ubicar" message:@"No hemos podido ubicar el usuario" delegate:nil cancelButtonTitle:@"Aceptar" otherButtonTitles:nil, nil]; [alerta show]; [alerta release]; } @end en el .h: #import #import "MapKit/MApKit.h" #import @interface PosicioGPSViewController : UIViewController { MKMapView *mapa; UIButton *pos; CLLocationManager *manager; NSString *latidutstri; NSString *longitudStri; } @property (nonatomic,retain) IBOutlet MKMapView *mapa; @property (nonatomic,retain) IBOutlet UIButton *pos; @property (nonatomic, retain) CLLocationManager *manager; -(IBAction)Posicio:(id)sender; @end Solo necessito recibir la posicion del iphone en newlocation.

6 Respuestas

0voto

Peter Puntos289170
En ningún lugar veo el código para "getCurrentLocation" entonces creo que te quieres referir a "currentLocation" en lugar de newlocation. ¿Correcto? Te dejo ejemplos de código para que pruebes. Locate Me. Demuestra los dos usos primarios para el "Core Location Framework" obtebiendo la localización del usuario y dandole seguimiento a los movimientos. CLLocationManager Class Reference Tienes 5 códigos de ejemplo para ver varias de las funciones que estas intentando realizar. Saludos.

0voto

markfree Puntos4510
Tenia entendido que la funcion que sirve para recibir la localizacion era la de – (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation Pero la que dices cual es? puedes passar la funcion? o el codigo? En algun tutorial funcionava correctamente, pero no se por que a my no me funciona. Cojen la latitud y longitud a traves del newLocation.coordinate.latitude newLocation.coordinate.longitude

0voto

Peter Puntos289170
Te puse arriba los dos enlaces con diferentes ejemplos y código para que descargues. Saludos.

0voto

markfree Puntos4510
Hola Peter, gràcias! no veo tus enlazes pero ya me funciona. Que pasada, se actualiza la bbdd y todo perfecto.... He borrado el hack y me ha funcionado!

0voto

markfree Puntos4510
Ok los veo gràcias otra vez!

0voto

Peter Puntos289170
Perfecto, que buno que ya te funciona todo :)

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

Otras Preguntas y Respuestas


Actividad Reciente

...