이 튜토리얼에 표시된대로 정확하게 내 iPhone 앱에 고지를 만들려고했습니다. http://www.youtube.com/watch?v=qNMNRAbIDoU 내 문제는 빌드하고 이동하지만지도가 표시되지만 Geolocation 서비스가 내 위치를 추적하지 못했지만, 그래서 난 그냥 세계지도를 볼 :( 여기 난 당신이 문제 그것을 식별하는 데 도움 수 있기를 바랍니다 내 코드입니다 :Geolocation 만 글로벌지도를 표시합니다.
appdelegate.h이
@interface WhereAmIAppDelegate : NSObject <UIApplicationDelegate,CLLocationManagerDelegate> {
UIWindow *window;
WhereAmIViewController *viewController;
CLLocationManager *locationManager;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) CLLocationManager *locationManager;
@property (nonatomic, retain) IBOutlet WhereAmIViewController *viewController;
appdelegate.m :
@implementation WhereAmIAppDelegate
@synthesize window;
@synthesize viewController;
@synthesize locationManager;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 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;
}
- (void)dealloc {
[viewController release];
[window release];
[super 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;
[viewController.mapView setRegion:region animated:YES];
viewController.mapView.showsUserLocation=YES;
viewController.latitude.text=[NSString stringWithFormat:@"%f",newLocation.coordinate.latitude];
viewController.longitude.text=[NSString stringWithFormat:@"%f",newLocation.coordinate.longitude];
}
@end
MyViewController.h
@interface WhereAmIViewController : UIViewController {
MKMapView *mapView;
UILabel *latitude;
UILabel *longitude;
}
@property (nonatomic,retain)IBOutlet MKMapView *mapView;
@property (nonatomic,retain)IBOutlet UILabel *latitude;
@property (nonatomic,retain)IBOutlet UILabel *longitude;
myViewController.m :
1) 시뮬레이터 위치가없는 것이 항상 위도/경도의 표시됩니다 :
@implementation WhereAmIViewController
@synthesize mapView;
@synthesize latitude;
@synthesize longitude;
- (void)dealloc {
[mapView release];
[latitude release];
[longitude release];
[super dealloc];
}
@end
두 라이브러리 Corelocation과 MapKit을 추가했음을 잊지 마십시오. – Malloc
실제 장치 또는 에뮬레이터를 사용하고 있습니까? AFAIK 에뮬레이터에는 GPS가 없지만 아마 에뮬레이터를 조롱 할 수 있습니다. –
나는 시뮬레이터를 사용하지만 튜토리얼에서 저자는 또한 시뮬레이터를 사용한다 : – Malloc