ios指南針的實現(CoreLocation)

來源:互聯網
上載者:User

標籤:

1.建立CLLocationManager對象,並且成為它的代理

- (CLLocationManager *)mgr{    if (!_mgr) {        _mgr = [[CLLocationManager alloc] init];    }    return _mgr;}
self.mgr.delegate = self;

2.開始擷取使用者位置

[self.mgr startUpdatingHeading];

3.在代理方法裡面實現功能

// 當擷取到使用者方向時就會調用- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading{//    NSLog(@"%s", __func__);    /*     magneticHeading 裝置與磁北的相對角度     trueHeading 設定與真北的相對角度, 必須和定位一起使用, iOS需要設定的位置來計算真北     真北始終指向地理北極點     *///    NSLog(@"%f", newHeading.magneticHeading);        // 1.將擷取到的角度轉為弧度 = (角度 * π) / 180;    CGFloat angle = newHeading.magneticHeading * M_PI / 180;    // 2.旋轉圖片    /*     順時針 正     逆時針 負數     *///    self.compasspointer.transform = CGAffineTransformIdentity;    self.compasspointer.transform = CGAffineTransformMakeRotation(-angle);                }

 

ios指南針的實現(CoreLocation)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.