Получить текущее местоположение пользователя в MKMapView

Я пытаюсь получить текущее последнее местоположение пользователя в методе didUpdateToLocation: newLocation: fromLocation: oldLocation: и сохранить его в моем ivar CLLocation * userCurrentLocation

Я получаю эту ошибку, когда я пытался прочитать кнопку userCurrentLocation

-[NSCFNumber coordinate]: unrecognized selector sent to instance 0x586b220



- (void) locationManager:(CLLocationManager *) manager
     didUpdateToLocation:(CLLocation *) newLocation
            fromLocation:(CLLocation *) oldLocation {
            fromLocation:(CLLocation *) oldLocation {
if (oldLocation == nil) { // first time loading? 
        SVGeocoder *geocodeRequest = [[SVGeocoder alloc] 
                                      initWithCoordinate:CLLocationCoordinate2DMake(newLocation.coordinate.latitude,     newLocation.coordinate.longitude)];
         [geocodeRequest setDelegate:self];
        [geocodeRequest startAsynchronous]; // reverse geocoding to get annotation coordinates to be placed.
        [geocodeRequest release];
        isCurrentLocation = YES; //flag that next annotation placed is current location
    }
        userCurrentLocation = newLocation;
NSLog(@"didUpdateToLocation - Lat:%f Long:%f", userCurrentLocation.coordinate.latitude, userCurrentLocation.coordinate.longitude); // verified that userCurrentLocation latitude is correct at this point.
}

на панели инструментов, чтобы показать текущее местоположение пользователя

-(IBAction) showLocation:(id) sender {
    NSLog(@"Lat:%f Long:%f", userCurrentLocation.coordinate.latitude, userCurrentLocation.coordinate.longitude); // crashes upon calling this statement. Why?
    NSLog(@"Show Location Called");
    SVGeocoder *geocodeRequest = [[SVGeocoder alloc] 
                                  initWithCoordinate:CLLocationCoordinate2DMake(userCurrentLocation.coordinate.latitude, userCurrentLocation.coordinate.longitude)];
    [geocodeRequest setDelegate:self];
    [geocodeRequest startAsynchronous];
    [geocodeRequest release];

}

Я установил свойство и синтезировал userCurrentLocation как таковой:

MapViewController.h

@interface MapViewController : UIViewController <CLLocationManagerDelegate,  MKMapViewDelegate> {
   CLLocation *userCurrentLocation;
}
@property (nonatomic, retain) CLLocation *userCurrentLocation;
@end

MapViewController.m

@synthesize userCurrentLocation;

          /* EDITED */
- (void)viewDidLoad {
    locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; 
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[locationManager startUpdatingLocation];
    userCurrentLocation = [[CLLocation alloc] init];
}
5
задан Gavin 29 August 2011 в 08:34
поделиться