【问题标题】:How to access precise user location in mapbox v10如何在 mapbox v10 中访问精确的用户位置
【发布时间】:2021-10-27 09:19:07
【问题描述】:

我正在尝试将相机移至用户位置。但是,使用

        let cameraOnUser = mapView.mapboxMap.camera(for: 
        mapView.location.latestLocation?.coordinate, padding: .zero, bearing: nil, pitch: nil)
    mapView.camera.ease(to: cameraOnUser, duration: 10.0)

不起作用,因为 mapView.location.latestLocation.coordinate 是辐射坐标,而不是精确的 CLLocationCorrdinate2D。查看 API 参考,Location.corrdinate 应该给我我需要的坐标,但是 XCode 不允许我在那个上下文中使用那个调用。计算路线适用于 latestLocation.corrdinate 但不适用于相机。 如何在新的 mapbox 版本中访问用户的位置?或者:有没有办法像我们在 v6.3.0 中一样使用 mapView.setUserTrackingMode(.follow, animates: true) 之类的东西?谢谢!我正在使用 mapboxMaps v10.0.1。

【问题讨论】:

    标签: swift xcode location mapbox


    【解决方案1】:

    camera(for: ...) 方法用于创建具有多个坐标、坐标边界或几何形状的相机。要创建具有单个坐标的相机,请手动创建 CameraOptions 结构:

    let coord = mapView.location.latestLocation?.coordinate
    let cam = CameraOptions(center: coord)
    mapView.camera.ease(to: cam, duration: 10.0)
    

    CameraOptions 包含以下属性,它们都有默认值,这就是为什么可以从初始化程序中省略任何或全部的原因:

    public var center: CLLocationCoordinate2D?
    public var padding: UIEdgeInsets?
    public var anchor: CGPoint?
    public var zoom: CGFloat?
    public var bearing: CLLocationDirection?
    public var pitch: CGFloat?
    

    【讨论】:

      猜你喜欢
      • 2022-12-30
      • 2015-01-24
      • 1970-01-01
      • 1970-01-01
      • 2022-08-18
      • 1970-01-01
      • 1970-01-01
      • 2022-10-21
      • 1970-01-01
      相关资源
      最近更新 更多