![](/img/trans.png)
[英]Why do I need to store a CLLocationManager to get the users location in MKMapView?
[英]iOS: Difference between the location I get from CLLocationManager and MKMapView's userLocation property
我有兩個視圖控制器: tweetViewController
和MapViewController
。 前者是供用戶發布推文的,其中我使用CLLocationManager
來獲取用戶的位置。 一旦locationManager:didUpdateToLocation:fromLocation:
被調用,我得到“ locationA”,我將提醒用戶已經設置了他的位置。
用戶可以通過“ locationA”發布該推文。 或通過單擊位置信息手動更改位置(以防位置不夠准確)。 在這種情況下, MapViewController
,並且有一個與locationA關聯的可拖曳的銷釘注釋落入地圖。 我發現別針與我的所在地相距數百米。 然后,我設置mapView.showUserLocation = YES
。 我發現藍色氣泡的位置比圖釘更准確。 所以,我的問題是如何在userLocation
中獲取mapView的tweetViewController
而不是從CLLocationManager
獲取位置。
我在中國,一直在尋找同樣的問題。 有人說中國的地圖已經變了,所以必須要有偏移量。 有什么建議可以解決這個問題嗎? 提前致謝。
最后 ,我使用MKMapView
實例來解決此問題。
設置
mapView.showUserLocation = YES/NO; //to start/stop locating.
使用
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
獲取用戶位置。 在我的控制器中,未顯示mapView
,它僅用於獲取用戶位置,並且該位置比我從locManager
獲得的位置更准確。
CLLocationManager
在所有實例中使用相同的數據。 MKMapView
內部使用CLLocationManager
的數據。 就是說,做您想要做的解決方案是讓MKMapView
就showUserLocation:
做自己的事情。 同時,創建CLLocationManager
及其委托的實例。
委托消息將為您提供MKMapView
的藍色圖釘的GPS坐標位置。 一切將彼此同步。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.