I have a GPX that simulates the movement to the coordinate. I can't get CLCircularRegion to fire for nothing. I've tried to put the code everywhere. Here's what I'm using:
var center: CLLocationCoordinate2D = CLLocationCoordinate2DMake(37.33171100, -122.03018400)
var radius: CLLocationDistance = CLLocationDistance(300)
var identifier: String = "Destination"
let region = CLCircularRegion(center: center, radius: radius, identifier: identifier)
manager!.startMonitoringForRegion(region)
I've placed this everywhere. I've put this in:
viewDidLoad
viewWillAppear
viewDidAppear
mapViewDidFinishLoadingMap(mapView: MKMapView!
mapViewDidFinishRenderingMap(mapView: MKMapView!, fullyRendered: Bool)
locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!)
Here is my GPX file:
<?xml version="1.0"?>
<gpx version="1.1" creator="Xcode">
<wpt lat="37.331711" lon="-122.030184">
<name>Apple</name>
</wpt>
<wpt lat="37.422455" lon="-122.084306">
<name>Google</name>
</wpt>
</gpx>
Println
works in didStartMonitoringRegion
and it prints the region's info to the logs but it doesn't fire. Nothing seems to work and its driving me insane. Here is my full program.
import UIKit
import CoreLocation
import MapKit
class ViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate {
var mapView: MKMapView?
var manager: CLLocationManager?
override func viewDidLoad() {
super.viewDidLoad()
mapView = MKMapView(frame: CGRectMake(0.0, 0.0, view.frame.size.width, view.frame.size.height))
self.mapView!.delegate = self
mapView!.showsUserLocation = true
view.addSubview(mapView!)
}
func locationManager(manager: CLLocationManager!, didEnterRegion region: CLRegion!) {
println("Entered")
}
func locationManager(manager: CLLocationManager!, didStartMonitoringForRegion region: CLRegion!) {
println("Monitoring")
println(region)
}
func mapViewDidFinishLoadingMap(mapView: MKMapView!) {
manager = CLLocationManager()
manager!.delegate = self
manager!.desiredAccuracy = kCLLocationAccuracyBest
manager!.startUpdatingLocation()
var center: CLLocationCoordinate2D = CLLocationCoordinate2DMake(37.33171100, -122.03018400)
var radius: CLLocationDistance = CLLocationDistance(300)
var identifier: String = "Destination"
let region = CLCircularRegion(center: center, radius: radius, identifier: identifier)
manager!.startMonitoringForRegion(region)
}
}
You have got to be kidding me. Its because I used NSLocationWhenInUseUsageDescription
instead of NSLocationAlwaysUsageDescription
in the info.plist