2011-04-03 33 views
1

我與模擬器地理位置奮力工作,但最近,我已經直接測試了設備(iPhone),但同樣的問題依然存在,這裏是我得到了什麼,當我的應用程序啓動完成和地理位置的代碼想給我的位置在地圖上(還記得上面的圖片是我在iPhone上的應用程序,而不是與模擬器):地理位置甚至沒有在設備

enter image description here

所以我的代碼,我的應用程序其實有很多的意見,但是關於這個功能,我已經在appdelegate(.m和.h)以及在地圖上顯示位置的視圖(PositionActuelleViewController)上工作。

appdelegate.m:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
    sleep(3); 




    // Override point for customization after application launch. 

    self.locationManager=[[[CLLocationManager alloc] init] autorelease]; 

    if([CLLocationManager locationServicesEnabled]) { 
     self.locationManager.delegate=self; 
     self.locationManager.distanceFilter=100; 
     [self.locationManager startUpdatingLocation]; 

    } 


     // Add the view controller's view to the window and display. 
    [window addSubview:viewController.view]; 
    [window makeKeyAndVisible]; 

    return YES; 
} 

,並在dealloc方法後,在同一個文件:

 #pragma mark CLLocationManagerDelegate Methods 


    -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 

     MKCoordinateSpan span; 
     span.latitudeDelta=0.2; 
     span.longitudeDelta=0.2; 


     MKCoordinateRegion region; 
     region.span=span; 
     region.center=newLocation.coordinate; 
     [viewCont.mapView setRegion:region animated:YES]; 

     viewCont.mapView.showsUserLocation=YES; 
     viewCont.latitude.text=[NSString stringWithFormat:@"%f",newLocation.coordinate.latitude]; 
     viewCont.longitude.text=[NSString stringWithFormat:@"%f",newLocation.coordinate.longitude]; 

} 

我PositionActuelleViewController.m文件:

#import "PositionActuelleViewController.h" 
@implementation PositionActuelleViewController 

@synthesize mapView; 
@synthesize latitude; 
@synthesize longitude; 

-(IBAction)goBackToMenu { 
    [self dismissModalViewControllerAnimated:YES]; 
} 
-(IBAction)goToRechercherView; 
{ 
    rechercherViewController.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal; 

    [self presentModalViewController:rechercherViewController animated:YES]; 

} 

- (void)didReceiveMemoryWarning { 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

- (void)viewDidUnload { 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (void)dealloc { 
    [mapView release]; 
    [latitude release]; 
    [longitude release]; 
    [super dealloc]; 
} 
@end 

缺少什麼我在這裏?

+0

我希望你不要忘記在IB中附加'mapView'? – 2011-04-03 15:20:19

+0

我做到了,如果它沒有連接它不會被執行,它會退出應用程序時的觀點是負載:) – Malloc 2011-04-03 15:26:55

+0

好吧,我剛剛檢查它在IB和它連接到我的文件的所有者:) – Malloc 2011-04-03 15:30:43

回答

0

是否委託方法-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation曾經被調用?也許如果您取消註釋self.locationManager.distanceFilter=100;它將工作,因爲根據文檔,distanceFilter屬性定義的最小距離(以米爲單位),生成一個更新事件之前,設備必須橫向移動。

+0

嗨kakoSquid,我已取消註釋self.locationManager.distanceFilter = 100;聲明,並嘗試建立,所以我的地圖顯示,我等了一段時間希望它的工作,但應用程序退出,我發現我的自我:(這是否意味着這可能是工作,當我移動此構建與iPhone上的這種修改?? thx – Malloc 2011-04-03 15:36:39

+0

我認爲這可能是一個原因你的問題......加上做註釋去掉睡眠(3),這可能導致不穩定的行爲 – 2011-04-03 15:38:22

+0

睡眠(3)是我的啓動畫面。 – Malloc 2011-04-03 15:39:48

相關問題