首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果我使用MKMapView,罗盘就不能在MKMapCamera上工作

如果我使用MKMapView,罗盘就不能在MKMapCamera上工作
EN

Stack Overflow用户
提问于 2016-04-13 06:01:55
回答 1查看 229关注 0票数 1

所以我试着做三件事。

  1. 有一张地图显示我的位置。
  2. 地图应该稍微倾斜,给人一种3d的感觉,就像我们在苹果地图上用两个手指上下滚动一样。
  3. 使用指南针旋转地图。

我已经在地图上启用了userTrackingMode,并且地图随指南针旋转,但是如果我在地图上设置了MKMapCamera,指南针就不能工作了。

这是我的密码。

代码语言:javascript
复制
    override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib.
            locationManager.desiredAccuracy = kCLLocationAccuracyBest
            locationManager.delegate = self
            locationManager.requestWhenInUseAuthorization()
            mapView.setUserTrackingMode(.FollowWithHeading, animated: true)
            locationManager.startUpdatingLocation()

        }


func locationManager(manager: CLLocationManager, didUpdateToLocation newLocation: CLLocation, fromLocation oldLocation: CLLocation) {


            let userCordinate = CLLocationCoordinate2D(latitude: newLocation.coordinate.latitude, longitude: newLocation.coordinate.longitude)

            let eyeCordinate = CLLocationCoordinate2D(latitude: newLocation.coordinate.latitude - 0.021078, longitude: newLocation.coordinate.longitude - 0.04078 )



            let mapCamera = MKMapCamera(lookingAtCenterCoordinate: userCordinate, fromEyeCoordinate: eyeCordinate, eyeAltitude: 1400)

            mapView.setCamera(mapCamera, animated: true)
            print("Camera set")

        }

我在这里做错什么了?

EN

回答 1

Stack Overflow用户

发布于 2017-01-06 04:18:12

你必须用指南针来更新相机的航向。下面是我目前正在使用的一些内容:

代码语言:javascript
复制
func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
        self.mapView.camera.heading = newHeading.trueHeading
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36589837

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档