Created
April 1, 2011 05:20
-
-
Save hagino3000/897783 to your computer and use it in GitHub Desktop.
Handle location event And HTTP get by Objective-C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(NSString*)locationString:(CLLocation *)newLocation { | |
NSDateFormatter * formatter = [[[NSDateFormatter alloc] init] autorelease]; | |
[formatter setTimeStyle:NSDateFormatterMediumStyle]; | |
return [NSString stringWithFormat:@"(%@) Location %.06f %.06f %@", ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) ? @"bg" : @"fg", newLocation.coordinate.latitude, newLocation.coordinate.longitude, [formatter stringFromDate:newLocation.timestamp]]; | |
} | |
- (void)locationManager:(CLLocationManager *)manager | |
didUpdateToLocation:(CLLocation *)newLocation | |
fromLocation:(CLLocation *)oldLocation | |
{ | |
NSLog(@"didUpdateToLocation!!"); | |
NSLog([ self locationString:newLocation ]); | |
NSLog(@"start send seerver"); | |
NSString * url; | |
NSString * state = ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) ? @"bg" : @"fg"; | |
url = [NSString stringWithFormat:@"http://49.212.11.68:3000/location?lat=%.06f&long=%.06f&type=%@", newLocation.coordinate.latitude, newLocation.coordinate.longitude, state]; | |
NSMutableURLRequest *request; | |
request = [[[NSMutableURLRequest alloc] init] autorelease]; | |
[request setURL:[NSURL URLWithString:url]]; | |
[request setCachePolicy:NSURLRequestUseProtocolCachePolicy]; | |
[request setTimeoutInterval:20]; | |
[request setHTTPShouldHandleCookies:FALSE]; | |
[request setHTTPMethod:@"POST"]; | |
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; | |
NSLog(@"END"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment