2011-03-28 2 views
1

이 튜토리얼에 표시된대로 정확하게 내 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 
+0

두 라이브러리 Corelocation과 MapKit을 추가했음을 잊지 마십시오. – Malloc

+0

실제 장치 또는 에뮬레이터를 사용하고 있습니까? AFAIK 에뮬레이터에는 GPS가 없지만 아마 에뮬레이터를 조롱 할 수 있습니다. –

+0

나는 시뮬레이터를 사용하지만 튜토리얼에서 저자는 또한 시뮬레이터를 사용한다 : – Malloc

답변

1

두 가지가 확인 캘리포니아에있는 Apple 본사
2) 위치가 정착되기까지 약간의 시간이 걸리므로 위치를 즉시 물어 보면 얻을 수 없습니다.

또한 WhereAmI보기 컨트롤러에 코드가 더 필요합니다. 보통 viewWillAppear에 뭔가가 표시됩니다. 보기 컨트롤러와 맵보기에 Here is a link to a Big Nerd Ranch tutorial. 어쩌면 그것은 당신을 도울 것입니다.

+0

파란색 핀이 Apple HQ에 있음을 발견했습니다. sim, CLLocationManager는 Wi-Fi 연결을 할 때와 관계없이 내 위치를 찾지 만 핀이 움직이지 않습니다 . –

1

주의 여기에 몇 가지가있다 : 그러나 그것은 1 무한 루프의 기본 위치를 가지고,

1) 아이폰 에뮬레이터에 GPS 기능이없는, 쿠퍼 티노, CA (미국)

2) 대리자 메서드는 이어야하며 didUpdateToLocation이 아니어야합니다.

+0

내 문제는 cuppertino에서 사과 위치를 추적하지 못한다는 것입니다. ( – Malloc