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

问题描述 投票:4回答:2

我在法国,当我尝试新的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)
}

我正在使用模拟器。

swift cllocationmanager
2个回答
12
投票

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

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

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

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

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


3
投票

除了Woodstock的答案,您还可以在方案中设置默认位置。它在运行/选项中。有一个选项可以允许位置模拟和一组可用于测试的标准默认值。有了更多选项,您可以将GPX文件添加到项目中。

© www.soinside.com 2019 - 2024. All rights reserved.