获取当前位置我的新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有差异输出。
你说“ipod”,你是指iPod Touch还是iPhone? – progrmr 2010-02-18 21:55:51