2010-02-17 57 views
0

獲取當前位置我的新iphone development.I正在創建一個地圖application.I已經使用按照頭文件錯誤而在地圖上

@interface BrusMapSubviewcontroller : UIViewController<UIApplicationDelegate,CLLocationManagerDelegate> { 
IBOutlet MKMapView *mapView; 

IBOutlet UIToolbar *toolbar; 
IBOutlet UIButton *location; 
IBOutlet UIButton *backtocampus; 
CLLocationManager *locationManager; 
} 

@property(retain,nonatomic) IBOutlet UIToolbar *toolbar; 
@property(retain,nonatomic) IBOutlet UIButton *location; 
@property(retain,nonatomic)IBOutlet UIButton *backtocampus; 
@property (nonatomic, retain) CLLocationManager *locationManager; 


-(IBAction) gosearch : (id) sender; 
-(IBAction) backtocampus: (id)sender; 

代碼在實現類

-(IBAction) gosearch : (id) sender{ 
self.locationManager = [[[CLLocationManager alloc] init] autorelease]; 
self.locationManager.delegate = self; 

[locationManager startUpdatingLocation]; 

NSLog(@"inside go search"); 

} 
    -(IBAction) backtocampus: (id)sender{ 

MKCoordinateRegion region; 
region.center.latitude=41.825672; 
region.center.longitude=-71.402695; 
region.span.latitudeDelta=0.001551; 
region.span.longitudeDelta=0.005493; 
mapView.mapType=MKMapTypeHybrid; 
mapView.region=region; 

NSLog(@"inside back to campus"); 
} 

- (void)locationManager: (CLLocationManager *)manager 
didUpdateToLocation: (CLLocation *)newLocation 
fromLocation:(CLLocation *)oldLocation 
{ 
[manager stopUpdatingLocation]; 
NSLog(@"inside update"); 
    printf("\n Latitude = %s\n Longitude = %s",[NSString stringWithFormat:@"%.7f",newLocation.coordinate.latitude],[NSString stringWithFormat:@"%.7f",newLocation.coordinate.longitude]); 

} 

- (void)locationManager: (CLLocationManager *)manager 
didFailWithError: (NSError *)error 
{ 
printf("\nerror"); 
} 

當我在模擬器中運行「裏面更新」打印在控制檯和長期和緯度values.But如果我在iPod中運行「內部去搜索」是單獨打印在console.Why在模擬器和device.Thanks有差異輸出。

+0

你說「ipod」,你是指iPod Touch還是iPhone? – progrmr 2010-02-18 21:55:51

回答

1

模擬器預設爲加利福尼亞州的一個地點(〜37.3,-122.0),因此當您在模擬器上啓動位置管理器時,您將立即與預設位置聯繫didUpdateToLocation:fromLocation:。這是你將從模擬器獲得的唯一位置。

在iPhone上,它可能需要幾秒到幾分鐘的時間,然後纔能有有效的GPS位置,因此可能需要一些時間才能看到「內部更新」消息或「錯誤」消息。但最終你應該得到一個或另一個。

您還可以更改distanceFilterdesiredAccuracy以控制您獲取位置更新的頻率。

0

iPod沒有嵌入GPS。所以我想這可能會導致這種功能障礙。

1

如果我明白你在問什麼,從模擬器到設備的區別的原因是;該模擬器預設爲位於CA位置的Apple。所以當你在設備上運行應用程序時,你會得到你當前的位置,當你在模擬器上運行應用程序時,你將在CA位置獲得Apple。

+0

我的模擬器沒有在ca位置顯示蘋果,它只是在console中打印座標,在地圖中加載該位置我應該怎麼做? – Warrior 2010-02-18 17:13:11