开发者

stop location updating on iPhone

开发者 https://www.devze.com 2023-03-19 20:05 出处:网络
I am using following code to stop location updating [locationManager stopUpdatingLocation]; locationManager.delegate = nil;

I am using following code to stop location updating

[locationManager stopUpdatingLocation];
locationManager.delegate = nil;

But still after calling thing function the location services are not stopp开发者_JS百科ed and still tries to find the location , can any one help me what I have done wrong.

thanks in advance.


Hopefully the following link could help you I guess.

http://www.iphonedevsdk.com/forum/iphone-sdk-development/2299-cllocationmanager-stopupdatinglocation-not-working.html


I had the same problem when it wouldn't stop updating location. I didn't try to nil the delegate though, because the problem was that in my "locationManager:didUpdateToLocation:fromLocation:" method was called other method before actually stopping updating location, i called my own method (download objects from server). It was okay until i had to download too many. I guess the deal is that it tries to download them too long for "didupdatelocation" to be called over and over again.

I thought of two solutions for that (for me at least):

  1. Do stuff AFTER stopping manager. - That didn't work for some reason, i still had multiple calls.
  2. Do stuff asynchronously. - That seemed to work well for me.

I hope this helps.


Normally the code you used [locationManager stopUpdatingLocation]; should work for stop updating location. But if that won't work then you can have one alternative soltion as follow:

-(void)viewDidLoad

{ firstTime = TRUE; }

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

if(firstTime = TRUE)
{
    firstTime = FALSE;
    current_Latitude=newLocation.coordinate.latitude;
    current_Longitude= newLocation.coordinate.longitude;
}

}

Here you can use one BOOL variable to check whether you updated the location or not.

0

精彩评论

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