Skip to content

Instantly share code, notes, and snippets.

@wizardishungry
Forked from tmiz/CoreLocationTest.m
Created June 18, 2013 20:55
Show Gist options
  • Select an option

  • Save wizardishungry/5809271 to your computer and use it in GitHub Desktop.

Select an option

Save wizardishungry/5809271 to your computer and use it in GitHub Desktop.

Revisions

  1. @tmiz tmiz revised this gist Dec 1, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion CoreLocationTest.m
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    // $ 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, 139.695538
    // 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 [email protected]
    //
  2. @tmiz tmiz revised this gist Dec 1, 2011. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion CoreLocationTest.m
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,6 @@
    // $ clang CoreLocationTest.m -framework cocoa -framework CoreLocation
    // $ ./a.out
    // location service enabled
    // 2011-12-01 21:03:01.836 a.out[10214:903] ----------------------------------------------------
    // 2011-12-01 21:03:01.839 a.out[10214:903] latitude,logitude : 35.606647, 139.695538
    // 2011-12-01 21:03:01.842 a.out[10214:903] timestamp : 2011-12-01 21:01:36 +0900
    // tmiz [email protected]
  3. @tmiz tmiz revised this gist Dec 1, 2011. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions CoreLocationTest.m
    Original file line number Diff line number Diff line change
    @@ -11,10 +11,8 @@
    #import <cocoa/cocoa.h>
    #import <CoreLocation/CoreLocation.h>

    CLLocationManager *manager;

    @interface NSObject(CB)
    - (void)logLocation:(CLLocation*)location;
    - (void)logLonLat:(CLLocation*)location;
    - (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation;
    - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error;
  4. @tmiz tmiz created this gist Dec 1, 2011.
    58 changes: 58 additions & 0 deletions CoreLocationTest.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    //
    // 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.836 a.out[10214:903] ----------------------------------------------------
    // 2011-12-01 21:03:01.839 a.out[10214:903] latitude,logitude : 35.606647, 139.695538
    // 2011-12-01 21:03:01.842 a.out[10214:903] timestamp : 2011-12-01 21:01:36 +0900
    // tmiz [email protected]
    //
    #import <cocoa/cocoa.h>
    #import <CoreLocation/CoreLocation.h>

    CLLocationManager *manager;

    @interface NSObject(CB)
    - (void)logLocation:(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;
    }