1

I am using

startMonitoringSignificantLocationChanges

for getting the (lat,lon) values.My problem is

  • (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

method doesn't gets called immediately after [locationMangerObject startMonitoringSignificantLocationChanges]; is encountered.Inside didUpdateToLocation method only i maintain two global double variables for holding latitude and longitude which will be set from the coordinates obtained from didUpdateToLocation method.These values are passed to the webservice,since didUpdateToLocation is called only a certain delay,between which the parameters for (lat,lon) takes zero as their value and passed to the service which results in an unexpected response.

How to make

  • (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

method to get called immediately after `[locationMangerObject startMonitoringSignificantLocationChanges]; is encountered.

Please anybody suggest me a solution for resolving this issue.

Thanks in advance.

Sankar Chandra Bose
  • 377
  • 1
  • 12
  • 27

4 Answers4

5

Maybe you should consider using startUpdatingLocation method instead of startMonitoringSignificantLocationChanges. From iOS docs:

startUpdatingLocation

This method returns immediately. Calling this method causes the location manager to obtain an initial location fix (which may take several seconds) and notify your delegate by calling its locationManager:didUpdateToLocation:fromLocation: method.

Community
  • 1
  • 1
jlajlar
  • 1,118
  • 11
  • 9
1

It can take several seconds to several minutes to get a good location depending on whether you have cell or wifi connection, and whether you have good signals from the GPS satellites. However, you should get a cached (possibly outdated) location right away.

Did you set the delegate for your locationMangerObject?

Did your function return to the runloop after calling the startMonitoringSignificantLocationChanges?

progrmr
  • 75,956
  • 16
  • 112
  • 147
  • I have set the delegate.After the control comes to [locationManagerObject startMonitoringSignificantLocationChanges]; it does not execute didUpdateToLocation.the exceution is directed to other statements in the viewDidLoad which are present after the locationManager initializations and other location manager stuffs,I am initializing the location manager in viewDidLoad – Sankar Chandra Bose Aug 23 '11 at 07:20
  • I am getting this message in the console,is it related to the location manager "Registration timer expired, but client is still registering!" – Sankar Chandra Bose Aug 23 '11 at 07:21
  • Can you show a little more of your code where you startMonitoring and when you expect the callback? – progrmr Aug 23 '11 at 14:44
0
///Hmmmmm

            ...CLLocationManager does n't call delegate method properly 
            ...after lot of R&D I'm  using a watchdog method it calls " -(void)locationadd " function every 10seconds and i'm using that location for drawing the path.

  -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
     {
     }       



 - (void)viewDidLoad
     {

   [NSTimer scheduledTimerWithTimeInterval:10
                                         target:self
                                           selector:@selector(locationadd)
                                           userInfo:nil
                                           repeats:YES];

        }


        -(void)locationadd   
        {

         if ([locationManager location]) {



        //i'm saving this location

    CLLocation *locat=locationManager.location;

     }

        }
        //
shankar
  • 239
  • 3
  • 5
0

This is because method startMonitoringSignificantLocationChanges() monitors significant changes in location. So it will not update location all time it is called when there will be measure difference in location or timestamp of past location update.

Better you use startUpdatingLocation() it will be called frequently so you will get location changes inside didUpdateLocations().

Omkar76
  • 1,317
  • 1
  • 8
  • 22