我是位置服務的新手。我已經使用startMonitoringSignificantLocationChanges
和(void)locationManager:(CLLocationManager *)manager didUpdateToLocation: (CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
方法,但它不會在我更改位置值時被調用。每當用戶改變其位置時,我都想獲取位置值。我應該如何實現這一點?請幫我解決。提前致謝。每當它改變位置時都要監視用戶的位置
回答
您需要實現「didUpdateLocations」委託方法。下面是示例
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(@"locations : %@",locations.description);
CLLocation *currentLocation = [locations lastObject];
NSLog(@"current location : %f %f",currentLocation.coordinate.latitude,currentLocation.coordinate.longitude);
}
請找到我更新的問題,是的,我也嘗試過這種方法,但它不工作。 – 2015-03-02 11:33:05
didUpdateToLocation方法已棄用。如果locationManager:didUpdateLocations:實現了 ,則不會調用此方法。一旦檢查它 – user4261201 2015-03-02 11:40:32
我使用你的updateLocation方法,那麼它不會被調用。爲什麼會這樣呢? – 2015-03-02 12:38:20
在iOS中8,你需要做兩個額外的東西來獲得位置工作: 1.添加下列鍵的一個或兩個,以你的Info.plist文件:
NSLocationWhenInUseUsageDescription NSLocationAlwaysUsageDescription
接下來,您需要爲相應的位置方法(WhenInUse或Background)請求授權。使用這些調用之一:
[self.locationManager requestWhenInUseAuthorization];
[self.locationManager requestAlwaysAuthorization];
有關詳細信息,請參閱以下鏈接。 http://nevan.net/2014/09/core-location-manager-changes-in-ios-8/
- 1. 當透視物體時改變位置
- 2. 位置管理器說,當它沒有位置改變
- 3. UIBackgroundModes位置和重要的位置更改與區域監測
- 4. Div當fadeIn()改變位置()
- 5. 當使用動畫時改變視圖的物理位置
- 6. 當iframe位置發生變化時更改窗口位置
- 7. MAPKIT當前用戶位置變化的監聽器Swift 3
- 8. 要求用戶訪問他們的位置時,使用iOS的位置,當mapView
- 9. 當我拖動它時,我的畫布正在改變位置
- 10. 當它改變時獲取可浮動的JToolBar位置
- 11. 改變位置
- 12. 改變位置
- 13. 監視android GPS位置
- 14. 改變用戶的體位配置
- 15. 當用戶改變其當前位置時,核心位置框架的哪個功能被調用?
- 16. 響應時間監視位置
- 17. 動畫標記當前位置上的位置改變
- 18. 啓動監視重要位置更改缺乏準確性
- 19. CLLocationManager - 監視區域與重要位置更改
- 20. 當用戶允許位置跟蹤時更新位置
- 21. 如何在div使用jQuery改變位置時進行監聽?
- 22. didUpdateLocations每當viewWillAppear調用重要位置時調用
- 23. WinAPI的:當位置有所改變
- 24. 用戶當前位置
- 25. 將WPF彈出位置時的WinForms窗口的位置改變
- 26. 如何獲取用戶每一小時的當前位置?
- 27. 改變Toastr位置?
- 28. 改變projct位置
- 29. 更改的位置,$位置
- 30. iOS在後臺監控用戶位置。
您是否分配了CLLocationManagerDelegate? – 2015-03-02 11:34:09
@DheerajSingh是的我已經使用myLocationManager.delegate = self;並分配給它的代表。 – 2015-03-02 12:39:19
是你使用ios8嗎?並可以顯示你的代碼 – 2015-03-02 12:55:27