2

我有一个模拟坐标移动的 GPX。我不能让 CLCircularRegion 白白开火。我试图将代码放在任何地方。这是我正在使用的:

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)

我到处都放了这个。我把这个放进去:

viewDidLoad 
viewWillAppear
viewDidAppear
mapViewDidFinishLoadingMap(mapView: MKMapView!
mapViewDidFinishRenderingMap(mapView: MKMapView!, fullyRendered: Bool)
locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!)

这是我的 GPX 文件:

<?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工作didStartMonitoringRegion并将该地区的信息打印到日志中,但它不会触发。似乎没有任何效果,它让我发疯。这是我的完整程序。

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)
   }
}
4

1 回答 1

3

你一定是在跟我开玩笑。它是因为我使用NSLocationWhenInUseUsageDescription而不是NSLocationAlwaysUsageDescriptioninfo.plist

于 2015-06-30T09:47:25.203 回答