2013年1月28日 星期一

[iOS] Update Locations


  • iOS 6建議使用 didUpdateLocations, 而非 didUpdateToLocation
  • iOS6之前
    • Controller 繼承 protocol <CLLocationManagerDelegate>
      • e.g. FirstViewController : UIViewController <CCLocationManagerDelegate>
    • 宣告一個 CLLocationManger 的 property並在 .m中 synthesize
      • e.g. @property (nonatomic, retain) CLLocationManager *locationManager; 
    • 實作 didUpdateToLocation: (CLLocation *) newLocation fromLocation: (CLLocation *)
      • e.g. 通常會將 outlet的 View其內容作設定
      • e.g. locationTextView.text = [NSString stringWithFormat: @"lat %+6.f", newLocation.coordination.latitude];
  • 改為覆寫 didUpdateLocations: (NSArray *) locations
    • 並用 [locations lastObject]來取用最新位置
  • Ref:

沒有留言:

張貼留言