我正在使用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
但是它非常紧张,任何想法我做错了什么?
答案 0 :(得分:0)
在整个UIview生命周期方法中分发您的locationManager
和mapView
方法,例如viewWillAppear
,viewDidAppear
等。
它应该给系统更多的时间来容纳初始化,而不是一次性抛出所有请求。