Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 获取错误的用户位置_Ios_Swift - Fatal编程技术网

Ios 获取错误的用户位置

Ios 获取错误的用户位置,ios,swift,Ios,Swift,你好,我刚刚开始学习swift ios-9。 我使用以下代码来获取用户的当前位置,但它正在获取位置 <+37.78583400,-122.40641700> +/- 5.00m (speed -1.00 mps / course -1.00) @ 1/8/16, 3:38:10 PM Greenwich Mean Time 我还将CoreLocation.framawork链接到我的项目。 由于我刚刚开始了解这一点,我没有苹果的开发者许可证。您无法在模拟器中模拟当前位置。您只能传递

你好,我刚刚开始学习swift ios-9。 我使用以下代码来获取用户的当前位置,但它正在获取位置

<+37.78583400,-122.40641700> +/- 5.00m (speed -1.00 mps / course -1.00) @ 1/8/16, 3:38:10 PM Greenwich Mean Time
我还将CoreLocation.framawork链接到我的项目。
由于我刚刚开始了解这一点,我没有苹果的开发者许可证。

您无法在模拟器中模拟当前位置。您只能传递坐标,模拟器将在地图中模拟这些坐标

要模拟自定义位置,请选择模拟器,然后从菜单中选择调试选项,然后选择位置,然后选择自定义位置

并输入自定义位置以模拟它:

要启用shouserLocation测试,请转到情节提要,选择地图视图,并在属性检查器中选择shwo用户位置选项


注意:您的当前位置只能在真实设备上显示。

r您在设备或模拟器上测试此功能?您是否已启用显示用户位置设置?我正在模拟器上测试,如何启用用户位置设置?
class ViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate {

    @IBOutlet weak var map: MKMapView!
    var manager:CLLocationManager!

    override func viewDidLoad() 
    {
        super.viewDidLoad()
        manager = CLLocationManager()
        manager.delegate = self
        manager.desiredAccuracy = kCLLocationAccuracyBest
        manager.requestWhenInUseAuthorization()
        manager.startUpdatingLocation()
    }

    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        print(locations[0])

        //userLocation - there is no need for casting, because we are now using CLLocation object

        let userLocation:CLLocation = locations[0]
        let latitude:CLLocationDegrees = userLocation.coordinate.latitude
        let longitude:CLLocationDegrees = userLocation.coordinate.longitude
        let latDelta:CLLocationDegrees = 0.01
        let lonDelta:CLLocationDegrees = 0.01
        let span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, lonDelta)
        let location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
        let region:MKCoordinateRegion = MKCoordinateRegionMake(location, span)
        map.setRegion(region, animated: true)
    }
}