Threading with LocationManager

Discussion in 'iOS Programming' started by oceandrive, Dec 11, 2008.

  1. oceandrive macrumors newbie

    Nov 17, 2008

    I need to get the Lat Long and submit to a web server.
    I followed the sample codes to get the lat/long using the LocationManager and then was able to submit the data to my webserver using the NSURL.

    I want to start a new thread on each click of a button on my app (which would do the above process) because I do not want to wait for the LocationManager to complete the task of getting Lat/Long data (Which is taking few seconds time and the app does not allow me to click on any other buttons).

    So I started of like this.

    [ NSThread detachNewThreadSelector: @selector(myThreadedMethod) toTarget: self withObject: nil ];
    - (void)myThreadedMethod
        NSAutoreleasePool *pool = [ [ NSAutoreleasePool alloc ] init ];
    	locmanager = [[CLLocationManager alloc] init]; 
    	[locmanager setDelegate:self]; 
    	[locmanager setDesiredAccuracy:kCLLocationAccuracyBest];	
    	[locmanager startUpdatingLocation];
        [ pool release ];
    But when I do this my didUpdateToLocation: is not getting called.

    Can someone guide me on if I am moving in the right direction or missing something.

    Thanks for the help.
  2. oceandrive thread starter macrumors newbie

    Nov 17, 2008
    Anybody any suggestions for me????


    I have now moved the submitToServer process to a Thread Method and it seems to be working fine, but still cant get the locationManager stuff to move to a Threaded method.


    1) Get the Lat/Long
    2) Create a new thread which does the submit to server.

    But would still like to know how we can do the threading on the locationManager.

  3. rahulvyas macrumors newbie

    May 6, 2009
    do not run/allocate location manager in another thread.Did you set CLLocationManagerDelegate in your header file? simulator will call the method didupdatetolocation only once while device call this multiple times.only allocate manager once and for getting new lat/long on button's click use [yourlocationmanagerObject startUpdatingLocation];

Share This Page