Die Suche nach Standort des Nutzers vor Kartenaufrufe

stimmen
1

Ich versuche, den Standort des Nutzers zu finden mit:

CLLocationCoordinate2D _location;
CLLocation *userLoc = nil;
if(appDelegate.clLocationManager.locationServicesEnabled){
    userLoc = mapView.userLocation.location;
    _location = userLoc.coordinate;
}

Das Problem ist, dass ich noch nicht die Karte initialisiert, so dass die oben nicht funktioniert. Gibt es eine Möglichkeit den Standort des Nutzers zu erhalten, ohne MapKit zu verwenden? Oder soll ich sein, eine andere Technik?

Veröffentlicht am 12/03/2010 um 21:34
quelle vom benutzer
In anderen Sprachen...                            


2 antworten

stimmen
1

Um den Standort des Nutzers zu erhalten müssen Sie eigentlich „Start“ den Standort-Manager, bevor Sie die Standort-Informationen zu lesen. Ich schlage vor, dass Sie bei LocateMe Probe von Apple aussehen.

LocateMe Beispielcode

Auf den Punkt gebracht, kann immer Benutzer-Standortinformationen in zwei Schritten erfolgen:

- (void)viewDidLoad {
    [[self locationManager] startUpdatingLocation];
}

- (CLLocationManager *)locationManager { 

    if (locationManager != nil) {       
        return locationManager; 
    }

    NSLog(@"%s, Creating new Location Manager instance.", __FUNCTION__);
    locationManager = [[CLLocationManager alloc] init]; 
    locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
    locationManager.distanceFilter = DISTANCE_FILTER_VALUE;
    locationManager.delegate = self; 

    return locationManager; 
}

... und dann,

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 
    NSLog(@"%s, location manager returned a new location.", __FUNCTION__);

    // Check if location is valid (or good enough for us), 
    // and then process the location
    if ([self locationIsValid:newLocation]) {
            [self processLocation:newLocation];

            // Very important! When your done with it, stop the location manager
            [[self locationManager] sopUpdatingLocation];

            // (Maybe even) clear it
            locationManager.delegate = nil;
            [locationManager release];
            locationManager = nil;
    }
}

Hoffe das hilft!

Beantwortet am 19/04/2010 um 11:46
quelle vom benutzer

stimmen
0

Ich löschte fast diese Frage aber sehen jemand es eine abstimmen gab. Dies scheint die Antwort zu sein:

CLLocationCoordinate2D _location;
CLLocation *userLoc = nil;
if(appDelegate.clLocationManager.locationServicesEnabled){
    userLoc = appDelegate.clLocationManager.location;
    _location = userLoc.coordinate;
}

AppDelegate ist nur ein Verweis auf die Anwendung delegiert, wo meine Standort-Manager-Instanz lebt.

Beantwortet am 12/03/2010 um 21:41
quelle vom benutzer

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