獲取當前位置我的新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