菜鸟教程小白 发表于 2022-12-11 19:13:58

ios - Swift 4 中的 mapView.setRegion


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

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

<pre><code>func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: ) {
      let location = locations
      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
      }
}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我敢打赌,您只是忘记将 mapView 与 Storyboard 链接起来。确保它作为@IBOutlet 正确连接,然后重试。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - Swift 4 中的 mapView.setRegion,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/47164399/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/47164399/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Swift 4 中的 mapView.setRegion