错误的位置 - 位于旧金山而不是法国

PMI*_*MIW 4 cllocationmanager swift

我在法国,当我尝试新func locationManager功能时,我的地图视图在旧金山找到了我.任何的想法?

override func viewDidLoad() {
    super.viewDidLoad()   

    if (CLLocationManager.locationServicesEnabled())
    {
        locationManager = CLLocationManager()
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.distanceFilter = kCLDistanceFilterNone
        locationManager.requestAlwaysAuthorization()
        locationManager.startUpdatingLocation()
    }
}

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
    let location = locations[locations.count-1] as CLLocation

    let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
    let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))

    self.map.setRegion(region, animated: true)
}
Run Code Online (Sandbox Code Playgroud)

我正在使用模拟器.

Woo*_*ock 14

iOS模拟器默认为美国 - San Fran,并不会估计您Mac的实际位置.

但是,您可以模拟移动甚至是特定位置,如下所示:

Simulator的Debug菜单下,最后一个条目是"Location"; 这为您提供了一个子菜单:

  • 没有
  • 自定义位置
  • Apple商店
  • 苹果
  • 城市自行车骑
  • 城市奔跑
  • 高速公路
  • 自定义位置可让您输入纬度/经度值.

骑自行车,城市奔跑和高速公路驾驶模拟移动位置(当然在库比蒂诺).