我要永遠對用戶位置爲中心的地圖,但我希望它永遠是在一個確切的縮放級別。我從這個answer得到的是,我不能沒有它縮放用戶位置使用userTrackingMode
。的iOS - 地圖用戶位置不居中
所以我創建了一個解決方法,按照用戶的位置
func updateRegion(withUserLocation userLocation: CLLocationCoordinate2D) {
var region = MKCoordinateRegion.init(center: userLocation, span: MapBodyViewConstants.zoomLevel)
// Avoid random spanning on the map by setting the region's span to be the same with the map's span
region.span = mapView.region.span
mapView.setRegion(region, animated: true)
}
的問題是,我從CLLocationManager
功能didUpdateLocations
獲得位置和locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
的manager.location?.coordinate
從locations.last?.coordinate
不同。這是一個小小的差異,但仍然存在差異(我應該提到,我只能通過無線網絡獲得這種差異)。
爲什麼有差異,我應該使用哪一個?經過一番研究,我得到了locations.last.coordinate
是首選,但我不知道(也認爲藍色的用戶點使用經理的位置,但不知道這一個)
還有一個問題:什麼iOS使用獲取地圖用戶藍點位置?它是位置管理器的座標還是什麼?
我希望這些問題是很清楚......
編輯:另外,我想我應該不在話下。問題不在MKMapViewDelegate
方法mapView(_ mapView: MKMapView, didUpdate userLocation: MKUserLocation)
。這工作正常。但在某些時候,當我啓動應用程序,我使用的位置,距離CLLocationManager
,這就是問題的所在