gpt4 book ai didi

ios - Mapbox 动画用户位置更流畅

转载 作者:行者123 更新时间:2023-11-28 11:15:32 25 4
gpt4 key购买 nike

我正在使用 Mapbox 并像这样实例化:

import MapboxGL


class RideViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate, MGLMapViewDelegate{
@IBOutlet weak var mapViewWrapper: UIView!
var mapView: MGLMapView!

override func viewDidLoad(){
// Location manager
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
locationManager.activityType = .Fitness

// Mapbox
mapView = MGLMapView(frame: mapViewWrapper.bounds, styleURL: NSURL(string: Mapbox.getTheme()))
mapView.autoresizingMask = .FlexibleWidth | .FlexibleHeight
mapView.userTrackingMode = .Follow
mapView.showsUserLocation = true
mapView.scrollEnabled = false
mapView.rotateEnabled = false
mapView.logoView.hidden = true
mapView.attributionButton.hidden = true
// set the map's center coordinate
mapView.setCenterCoordinate(appleMap.userLocation.coordinate,
zoomLevel: 12, animated: true)
mapViewWrapper.addSubview(mapView)

}

func locationManager(manager:CLLocationManager, didUpdateLocations locations:[AnyObject]) {
myLocations.append(locations[0] as! CLLocation)
mapView.setCenterCoordinate(appleMap.userLocation.coordinate, zoomLevel: 16, animated: true)
}

}

如您所见,我有 animated: true 但它非常不稳定,知道我做错了什么吗?

最佳答案

您没有做错任何事情,该库仍处于测试阶段,他们正在努力使用户跟踪更加顺畅。发生的事情是用户位置图标立即移动到它的新位置,但 map 动画到它的新中心。这让人感觉相当紧张。需要的是根据用户的速度和路线为 map (如果需要,还可以添加用户图标)制作动画。

但是,您的做法很艰难。您无需创建自己的位置管理器和设置 map 中心,只需设置 mapView.userTrackingMode 即可跟随用户。

关于ios - Mapbox 动画用户位置更流畅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32025026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com