-
-
Save roxlu/3c899602069a7b471cae to your computer and use it in GitHub Desktop.
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
import Foundation | |
import UIKit | |
import CoreLocation | |
class NewsLocationViewController : | |
UIViewController, | |
CLLocationManagerDelegate { | |
var location_manager: CLLocationManager! | |
override func loadView() { | |
super.loadView(); | |
location_manager = CLLocationManager() | |
location_manager.delegate = self | |
location_manager.distanceFilter = 3000 | |
location_manager.desiredAccuracy = kCLLocationAccuracyKilometer | |
view.backgroundColor = .redColor(); | |
location_manager.requestAlwaysAuthorization() | |
} | |
/* ----------------------------------------------------------------------------------------------------- */ | |
/* CLLocationManagerDelegate */ | |
/* ----------------------------------------------------------------------------------------------------- */ | |
func locationManager(manager: CLLocationManager!, | |
didChangeAuthorizationStatus status: CLAuthorizationStatus) | |
{ | |
println("Received authorization update."); | |
switch (status) { | |
case .NotDetermined: | |
println(".NotDetermined") | |
case .Restricted: | |
println(".Restricted access to location manager.") | |
case .Denied: | |
println(".Denied.") | |
case .Authorized: | |
println(".Always authorized ot use location manager.") | |
location_manager.startUpdatingLocation(); | |
case .AuthorizedWhenInUse: | |
println(".AuthorizedWhenInUse") | |
} | |
} | |
func locationManager( manager: CLLocationManager!, | |
didUpdateLocations locations: [AnyObject]!) | |
{ | |
let geocoder = CLGeocoder() | |
let placemark_cb: (([AnyObject]!, NSError!)-> Void) = | |
{ | |
(placemarks, error) in | |
if nil != error { | |
println("\(error!)") | |
return | |
} | |
for placemark in placemarks as [CLPlacemark] { | |
println("\(placemark.locality)") | |
println("\(placemark.administrativeArea)") | |
println("\(placemark.country)") | |
println("\(placemark.thoroughfare)") | |
println("\(placemark.subThoroughfare)") | |
} | |
return | |
}; | |
for loc in locations { | |
geocoder.reverseGeocodeLocation(loc as? CLLocation, completionHandler: placemark_cb); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment