2012-04-10 16 views
1

コンパスを表示したいアプリケーションを1つ作成しました。私のアプリケーションは空白ページを表示しています。CoreLocationフレームワークも追加しました。コンパスを表示するのを手伝ってください。コンパスがiphoneに表示されない

.hファイルコード:

import "UIKit/UIKit.h" 
import "CoreLocation/CoreLocation.h" 

@interface Compass_VIew : UIViewController<CLLocationManagerDelegate> 
    { 

IBOutlet UIImageView *arrow; 

IBOutlet UIImageView *arrowC; 

CLLocationManager *locManager; 

} 

@property (nonatomic, retain) CLLocationManager *locManager; 

@property(readonly, nonatomic) BOOL headingAvailable; 

@end 

.mファイルコード

didUpdateHeadingメソッドコード:

NSLog(@"New magnetic heading: %f", newHeading.magneticHeading); 
NSLog(@"New true heading: %f", newHeading.trueHeading); 

viewDidLoadメソッドコード:あなたが与える必要が

[super viewDidLoad]; 
// Do any additional setup after loading the view from its nib. 
[[self navigationController] setNavigationBarHidden:NO animated:NO]; 
locManager = [[[CLLocationManager alloc] init] autorelease]; 
locManager.desiredAccuracy= kCLLocationAccuracyBest; 
locManager.delegate = self; 
[self.locManager startUpdatingHeading]; 
+0

それは任意のエラーや警告を与えているインポートすることを忘れてはいけませんか? –

答えて

2

ニードルの変換それはこの

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    self.view.backgroundColor = [UIColor clearColor]; 

    locationManager = [[CLLocationManager alloc] init]; 
    locationManager.delegate = self; 
    locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
    locationManager.distanceFilter = kCLDistanceFilterNone; 
    [locationManager startUpdatingLocation]; 
    [locationManager startUpdatingHeading]; 

    CLLocation *location = [locationManager location]; 
    CLLocationCoordinate2D user = [location coordinate]; 


} 

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 
    CLLocationCoordinate2D here = newLocation.coordinate; 


} 

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading { 

    double trueheading = newHeading.magneticHeading; 
    double northangle = (trueheading*M_PI/180); 
    redPin.transform = CGAffineTransformMakeRotation(northangle); 
} 

ようにする必要がありコンパス

のeはここにredPinは私の針の図であり、方法によってCoreLocationフレームワーク

+0

redpinはimageviewで、ImageViewオブジェクトでバインドしています...私は正しいですか? –

+0

はいそれはイメージビューです – Charan

+0

ありがとうございました。私の電話は今コンパスを表示しています... @Sree charan –

関連する問題