Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

oceandrive

macrumors newbie
Original poster
Nov 17, 2008
28
0
Case:

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.

Code:
[ NSThread detachNewThreadSelector: @selector(myThreadedMethod) toTarget: self withObject: nil ];

Code:
- (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.
 
Anybody any suggestions for me????

Update:

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.

OnButtonPress

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.

Thanks
 
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];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.