Recuperar UserLocation Coordinar con MapKit

votos
5

I m usando MapKit en mi solicitud y disaply la ubicación del usuario con


[mapview setShowUserLocation:YES];

Quiero configurar el region.center.latitude y region.center.longitude con la coordenada del userLocation, cómo hacerlo?

Publicado el 01/02/2010 a las 11:34
fuente por usuario
En otros idiomas...                            


5 respuestas

votos
10

Aquí está mi respuesta, intento algo por el estilo y su trabajo:


//inside my ViewDidLOad
locManager = [[CLLocationManager alloc] init];
[locManager setDelegate:self];
[locManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locManager startUpdatingLocation];

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation  {
CLLocationCoordinate2D loc = [newLocation coordinate]; [maptView setCenterCoordiante:loc]; }
Respondida el 10/03/2010 a las 11:43
fuente por usuario

votos
6

Más fácil:

-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.location.coordinate, 1500, 1500);
[mapView setRegion:region animated:YES];
}
Respondida el 15/08/2012 a las 14:52
fuente por usuario

votos
2

Por alguna razón, esto no funcionó para mí. Me está tomando a las coordenadas (0.0000, 0.0000). A continuación se muestra el código si usted tiene la oportunidad de comprobarlo. ¡Gracias por la ayuda!

[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
mapView.showsUserLocation=TRUE;

MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };

CLLocationCoordinate2D myCoord = {mapView.userLocation.location.coordinate.latitude,mapView.userLocation.location.coordinate.longitude};
[mapView setCenterCoordinate:myCoord animated:YES];

region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES]; 

[mapView setDelegate:self];
Respondida el 20/12/2010 a las 09:47
fuente por usuario

votos
1

Creo que esto responde a su pregunta: Volviendo MapKit Userlocation Coordenadas

(utiliza la mapView.userLocation.location.coordinate.latitudey mapView.userLocation.location.coordinate.longitude properties)

y luego inyectar esas coordenadas en el

-(void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate animated:(BOOL)animated

de la instancia MKMapView.

Respondida el 01/02/2010 a las 11:41
fuente por usuario

votos
0

Usando delegado:

  1. Añadir MapKit delegado: MKMapViewDelegate
  2. Lograr método: MapView didUpdateUserLocation
    -(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
        MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.location.coordinate,
            500, 500);
        [mapView setRegion:region animated:YES];
    }
    

Sin delegado:

[self.mapView setuserTrackingMode:MKUserTrackingModeFollow];
Respondida el 23/05/2019 a las 04:03
fuente por usuario

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more