トップ «前の日記(2013-07-20) 最新 次の日記(2013-08-07)» 編集

Cocoa練習帳

iOS/iPhone/iPad/watchOS/tvOS/MacOSX/Android プログラミング, Objective-C, Cocoa, Swiftなど

2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|09|10|11|12|
2024|01|02|03|

2013-07-21 [iOS]AR(位置情報)

現在地情報を取得してみる。

プロジェクトに、CoreLocation.frameworkを追加する。

CLLocationManagerDelegateプロトコルを採用する。

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
 
@interface ViewController : UIViewController <CLLocationManagerDelegate>
 
@property (weak, nonatomic) IBOutlet UIView *augmentedRealityView;
 
@end

CLLocationManagerクラスのインスタンスを生成して、現在地の更新を開始する。

    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;
    [self.locationManager startUpdatingLocation];

現在地の更新を受け取る。

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    CLLocation  *newLocation = [locations lastObject];
    CLLocationCoordinate2D  newCoordinate = newLocation.coordinate;
    DBGMSG(@"new latitude=%f, longitude=%f", newCoordinate.latitude, newCoordinate.longitude);
}

デバイスの情報も取得してみよう。

電子コンパスが仕様可能な場合は、測定を開始する。

    if ([CLLocationManager headingAvailable]) {
        [self.locationManager startUpdatingHeading];
    }

方位の更新を受け取る。

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
    DBGMSG(@"trueHeading %f, magneticHeading %f", newHeading.trueHeading, newHeading.magneticHeading);
}

_ ソースコード

GitHubからどうぞ。
https://github.com/murakami/workbook/tree/master/ios/AugmentedReality - GitHub


_ 【Cocoa練習帳】

http://www.bitz.co.jp/weblog/
http://ameblo.jp/bitz/(ミラー・サイト)

トップ «前の日記(2013-07-20) 最新 次の日記(2013-08-07)» 編集