开发者

didUpdateToLocation doesn't gets called immediately

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.


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.


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?


///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;

     }

        }
        //


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().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜