2013-06-22 2 views
-1

나는 지정된 위치와 현재 위치 사이의 거리를 찾는 앱을 만들고 있습니다. 동일한 번호로 CLLocationManager을 사용하고 있지만 시뮬레이터에서 사용자 지정 위치를 지정 했음에도 불구하고 가져온 좌표는 0,0입니다. 여기 코드는 다음과 같습니다 는 lattitude이 내 코드 문제 zero.Anything로 기록됩니다iOS에서 현재 위치를 검색하려고합니다.

@property (nonatomic, strong) CLLocationManager *locationManager2; 
... 
@synthesize locationManager2; 
- (CLLocationManager *)locationManager2 { 

if (locationManager2 != nil) { 
    return locationManager2; 
} 

locationManager2 = [[CLLocationManager alloc] init]; 
[locationManager2 setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters]; 
[locationManager2 setDelegate:self]; 

return locationManager2; 
} 
... 
... 
... 
    CLLocation *locationHome = [locationManager2 location]; 

NSLog(@"%f",locationHome.coordinate.latitude); 

하는 .m 파일?

+0

시뮬레이터에 내장

이 코드는 위치를 제공하는 지원하지 않습니다. 당신은 장치를 사용해야합니다. – Geek

+0

(ios 6) .. –

+3

이것은 위치 관리자가 작동하는 방식이 아닙니다. 위치 서비스를 시작하고 위임 메소드에 대한 호출을 기다려야합니다. 안정적으로 위치 관리자 객체를 생성하고 그 위치를 조회 할 수는 없습니다. 이것은 비동기 적으로 발생합니다. [위치 인식 프로그래밍 가이드] (http://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html#//apple_ref/doc/uid/TP40009497-CH2-SW9)를 참조하십시오.). – Rob

답변

0

이 코드를 입력하고 콘솔에서 무엇을 얻고 있는지 알려주십시오. 아이폰 OS 6

CLLocationManager *locationManager = [[CLLocationManager alloc] init]; 
if ([CLLocationManager locationServicesEnabled]) 
{ 
    locationManager.delegate = self; 
    locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
    locationManager.distanceFilter = kCLDistanceFilterNone; 
    [locationManager startUpdatingLocation]; 
} 

location = [locationManager location]; 
CLLocationCoordinate2D coordinate = [location coordinate];; 
MKCoordinateRegion region; 
region.center=coordinate; 
MKCoordinateSpan span; 
span.latitudeDelta=10.015; 
span.longitudeDelta=10.015; 
region.span=span; 
[mapView setRegion:region]; 

NSString *str=[[NSString alloc] initWithFormat:@" latitude:%f longitude:%f",coordinate.latitude,coordinate.longitude]; 
NSLog(@"%@",str); 
관련 문제