1
votes

I have a question about location.

I need to get location of latitude and longitude at iOS 5.1 and iOS 6 upper.

But I write NSLog in didUpdateLocations and didUpdateToLocation function .

I had not saw the log show in console.

I am use simulate set location . I am test latitude value is 25.317973, longtitude value is 121.538161 (D1).

Then I am test value is ( 25.917973, 121.538161 ) (D2).

D1 and D2 distance is more than 10 meter;

But I never saw the log show in console.

I attach my code below:

my .h file

#mport <GoogleMaps/GoogleMaps.h>
#import <CoreLocation/CoreLocation.h>
#import <Corelocation/CLLocationManagerDelegate.h> 

@interface LocationMapViewController : AbstractViewController<     CLLocationManagerDelegate, GMSMapViewDelegate >
@property (strong, nonatomic) CLLocationManager *locationManager;
@end

my .m file

   - (void)viewDidLoad
       {
           [super viewDidLoad];

 if( _locationManager == nil )
    {
        _locationManager =  [CLLocationManager new];
        _locationManager.delegate = self;

        _locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        _locationManager.distanceFilter = 10.0f;
        [_locationManager startUpdatingHeading];

    }

-(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray     *)locations
{
    NSLog(@"==latitude %f, longitude %f", [[locations objectAtIndex:([locations     count]-1)] coordinate].latitude , [[locations objectAtIndex:([locations count]-1)]     coordinate].longitude);
}

-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation     *)newLocation fromLocation:(CLLocation *)oldLocation
{
     NSLog(@"====latitude %f, longitude %f", newLocation.coordinate.latitude,     newLocation.coordinate.longitude);
}

Have anyone know what's wrong with my code?

thank you very much

1

1 Answers

1
votes

You do not have to import the CLLocationManagerDelegate in your .h and AFAIK I think CoreLocation is not using Google Maps as well, so unless you are using the Google Maps API or something there should be no need to import the GoogleMaps as well.

Try using this instead in your method:

- (void)viewDidLoad
{
    [super viewDidLoad];

    if( _locationManager == nil )
    {
       _locationManager = [[CLLocationManager alloc] init];
       _locationManager.delegate = self;
       _locationManager.desiredAccuracy = kCLLocationAccuracyBest;

       [_locationManager startUpdatingLocation];
    }
}

edit:

I realised that you are trying to get the difference in the distance. So maybe just change your

_locationManager = [CLLocationManager new];

to

_locationManager = [[CLLocationManager alloc] init];

and that should solve the problem.

Following your comment, I have checked a little more, and realised that you are using the startUpdatingHeading method call, therefore you should be using the didUpdateHeading delegate methods. This is from the Apple CLLocationManager reference:

Heading events are delivered to the locationManager:didUpdateHeading: method of your delegate. If there is an error, the location manager calls the locationManager:didFailWithError: method of your delegate instead.

Hope this helps! :)