2010-02-17 58 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