Hent UserLocation Koordinere med MapKit

stemmer
5

I m bruke MapKit i søknaden min og disaply brukerstedet med


[mapview setShowUserLocation:YES];

Jeg ønsker å sette region.center.latitude og region.center.longitude med koordinat for userLocation, hvordan du gjør det?

Publisert på 01/02/2010 klokken 10:34
kilden bruker
På andre språk...                            


5 svar

stemmer
10

Her er mitt svar, jeg prøver noe sånt og arbeids:


//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]; }
Svarte 10/03/2010 kl. 10:43
kilden bruker

stemmer
6

Mye enklere:

-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.location.coordinate, 1500, 1500);
[mapView setRegion:region animated:YES];
}
Svarte 15/08/2012 kl. 13:52
kilden bruker

stemmer
2

For noen grunn, gjorde dette ikke fungerer for meg. Det tar meg til koordinatene (0,0000, 0,0000). Nedenfor er min kode hvis du har en sjanse til å sjekke det ut. Takk for hjelpen!

[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];
Svarte 20/12/2010 kl. 08:47
kilden bruker

stemmer
1

Jeg tror dette besvarer ditt spørsmål: Retur Mapkit Userlocation koordinater

(bruker mapView.userLocation.location.coordinate.latitudeog mapView.userLocation.location.coordinate.longitude properties)

og deretter injisere disse koordinatene i

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

av MKMapView eksempel.

Svarte 01/02/2010 kl. 10:41
kilden bruker

stemmer
0

Bruke delegat:

  1. Legg Mapkit delegat: MKMapViewDelegate
  2. Oppnå metode: MapView didUpdateUserLocation
    -(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
        MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.location.coordinate,
            500, 500);
        [mapView setRegion:region animated:YES];
    }
    

Uten delegat:

[self.mapView setuserTrackingMode:MKUserTrackingModeFollow];
Svarte 23/05/2019 kl. 04:03
kilden bruker

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