CoreLocation with Nu

Here’s another fun Nu script; like the previous one, you’ll need something from my Nu github repository to run it.

#!/usr/local/bin/nush
(load "CoreLocation")

(class MyDelegate is NSObject

  (- (void) locationManager:(id) mgr 
            didUpdateToLocation:(id) newLocation 
            fromLocation:(id) oldLocation is
     (puts "updated location")
     (puts (+ "new location: " (newLocation description)))
     (puts (+ "old location: " (oldLocation description))))

  (- (void) locationManager:(id) mgr didFailWithError:(id) error is
     (puts "error")
     (puts (error description))))

(set delegate (MyDelegate new))

(set cl (CLLocationManager new))
(cl setDelegate:delegate)
(cl startUpdatingLocation)

(puts "run for a while")
((NSRunLoop mainRunLoop) runUntilDate:
    (NSDate dateWithTimeIntervalSinceNow:5))
(puts "done")

Comment on this post ↓

Leave a Comment (sign in with Twitter)