Recupera UserLocation coordinate con MapKit

voti
5

I m utilizzando MapKit nella mia applicazione e disaply la posizione dell'utente con


[mapview setShowUserLocation:YES];

Voglio impostare il region.center.latitude e region.center.longitude con la coordinata del userLocation, come fare?

È pubblicato 01/02/2010 alle 11:34
fonte dall'utente
In altre lingue...                            


5 risposte

voti
10

Ecco la mia risposta, cerco qualcosa di simile e il suo funzionamento:


//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]; }
Risposto il 10/03/2010 a 11:43
fonte dall'utente

voti
6

Molto più facile:

-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.location.coordinate, 1500, 1500);
[mapView setRegion:region animated:YES];
}
Risposto il 15/08/2012 a 14:52
fonte dall'utente

voti
2

Per qualche ragione, questo non ha funzionato per me. Mi sta prendendo alle coordinate (0.0000, 0.0000). Qui di seguito è il mio codice, se si ha la possibilità di check it out. Grazie per l'aiuto!

[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];
Risposto il 20/12/2010 a 09:47
fonte dall'utente

voti
1

Penso che questo risponde alla tua domanda: Tornando MapKit Userlocation Coordinate

(usa la mapView.userLocation.location.coordinate.latitudee mapView.userLocation.location.coordinate.longitude properties)

e poi iniettare quelle coordinate nel

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

dell'istanza MKMapView.

Risposto il 01/02/2010 a 11:41
fonte dall'utente

voti
0

Utilizzando delegato:

  1. Aggiungere MapKit delegato: MKMapViewDelegate
  2. Metodo di realizzare: MapView didUpdateUserLocation
    -(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
        MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.location.coordinate,
            500, 500);
        [mapView setRegion:region animated:YES];
    }
    

Senza delegato:

[self.mapView setuserTrackingMode:MKUserTrackingModeFollow];
Risposto il 23/05/2019 a 04:03
fonte dall'utente

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