2012-04-10 102 views
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

是它給予任何錯誤或警告? – 2012-04-10 06:14:47

回答

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); 
} 

這裏redPin我的針看法和方式,不要忘記導入CoreLocation框架

+0

redpin是imageview,你用ImageView對象綁定它...我是嗎? – 2012-04-10 08:29:46

+0

是的它是圖像視圖 – Charan 2012-04-10 09:19:55

+0

謝謝..我的手機現在正在顯示指南針... @Sree charan – 2012-04-11 08:58:50