 //
 import CoreLocation
 
-public class Tracker: NSObject, CLLocationManagerDelegate{
-    var distance: Double?
+public class Tracker: NSObject, CLLocationManagerDelegate {
+    public var distance: Double = 20.0
+    public var radius: Double = 200.0
+    public var accuracy: Double = kCLLocationAccuracyHundredMeters
+    
     var latitude: Double?
     var longitude: Double?
-    var radius: Double?
-    var accuracy: Double?
+    
     var loc_name: String?
-    var locationDic: Dictionary<String,Double> = [:]
+    var locationDic: [String: [String: Any]] = [:]
     private var myLocation = CLLocation()
     private let locationManager = CLLocationManager()
+    
+    public func getDistance() -> Double? {
+        return self.distance
+    }
     
     required public override init() {
         super.init()

        let center = CLLocationCoordinate2DMake(latitude, longitude)
        let monitoringRegion = CLCircularRegion.init(center: center, radius: radius, identifier: name)
        locationManager.startMonitoringForRegion(monitoringRegion)
        self.locationDic[name] = distance
    }
    
    public func removeLocation(name: String) {

    
    public func locationManager(manager: CLLocationManager, didEnterRegion region: CLRegion) {
        locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
        self.locationDic[region.identifier]!["withinRegion"] = true
        print("did enter region \(region.identifier)")
    }
    
    public func locationManager(manager: CLLocationManager, didExitRegion region: CLRegion) {
        print("did exit region \(region.identifier)")
        self.locationDic[region.identifier]!["withinRegion"] = false
        self.locationDic[region.identifier]!["notifiedForRegion"] = false
        
        if outOfAllRegions() {
            locationManager.desiredAccuracy = self.accuracy
        }
    }
    
    private func outOfAllRegions() -> Bool {
        for (region, regionInfo) in self.locationDic {
            if regionInfo["withinRegion"] as! Bool{
                return false
            }
        }
        return true
    }
    
}