Created
December 1, 2011 12:08
-
-
Save tmiz/1416248 to your computer and use it in GitHub Desktop.
Using CoreLocation on Mac OS X with command-line
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
// | |
// Using CoreLocation on Mac OS X with command-line | |
// $ clang CoreLocationTest.m -framework cocoa -framework CoreLocation | |
// $ ./a.out | |
// location service enabled | |
// 2011-12-01 21:03:01.839 a.out[10214:903] latitude,logitude : 35.606647, 140.695538 | |
// 2011-12-01 21:03:01.842 a.out[10214:903] timestamp : 2011-12-01 21:01:36 +0900 | |
// tmiz moo@tmiz.net | |
// | |
#import <cocoa/cocoa.h> | |
#import <CoreLocation/CoreLocation.h> | |
@interface NSObject(CB) | |
- (void)logLonLat:(CLLocation*)location; | |
- (void)locationManager:(CLLocationManager *)manager | |
didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation; | |
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error; | |
@end | |
@implementation NSObject(CB) | |
- (void)logLonLat:(CLLocation*)location | |
{ | |
CLLocationCoordinate2D coordinate = location.coordinate; | |
NSLog(@"latitude,logitude : %f, %f", coordinate.latitude, coordinate.longitude); | |
NSLog(@"timestamp : %@", location.timestamp); | |
} | |
- (void)locationManager:(CLLocationManager *)manager | |
didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { | |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
[self logLonLat:newLocation]; | |
[pool drain]; | |
} | |
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{ | |
NSLog(@"Error: %@", error); | |
} | |
@end | |
int main(int ac,char *av[]) | |
{ | |
id obj = [[NSObject alloc] init]; | |
id lm = nil; | |
if ([CLLocationManager locationServicesEnabled]) { | |
printf("location service enabled\n"); | |
lm = [[CLLocationManager alloc] init]; | |
[lm setDelegate:obj]; | |
[lm startUpdatingLocation]; | |
} | |
CFRunLoopRun(); | |
[lm release]; | |
[obj release]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm trying to run this code on my terminal(Mac OS X 10.9 Xcode 4.2).but got error message can not find the .h file