OGeek|极客世界-中国程序员成长平台

标题: ios - Swift 4 中的 mapView.setRegion [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:13
标题: ios - Swift 4 中的 mapView.setRegion

我在 Swift 4、Xcode 9 中的代码有问题。有人可以帮我吗? 当我运行这个程序时,它给了我一个错误。

它说 mapView.setRegion(region, animated: true) 不起作用并给我一个错误,当我将其注释掉时,它适用于我当前的位置,但只是没有放大。

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        let location = locations[0]
        if !isInitialized {
            isInitialized = true
            let span:MKCoordinateSpan = MKCoordinateSpanMake(0.01, 0.01)
            let myLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude)
            let region:MKCoordinateRegion = MKCoordinateRegionMake(myLocation, span)
            mapView.setRegion(region, animated: true)
            self.mapView.showsUserLocation = true
        }
}



Best Answer-推荐答案


我敢打赌,您只是忘记将 mapView 与 Storyboard 链接起来。确保它作为@IBOutlet 正确连接,然后重试。

关于ios - Swift 4 中的 mapView.setRegion,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47164399/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4