2010-07-01 5 views
12

사용자가지도를 스크롤 할 수있는 MKMapView가 있습니다. 나중에지도 중심에서 위도와 경도를 가져오고 싶지만 쉽게 할 수는 없습니다. 현재로서는 다음과 같은 것을 시도하고 있습니다.MKMapView지도의 중심을 얻는 방법은 무엇입니까?

CLLocationCoordinate2D centre = [locationMap convertPoint:locationMap.center toCoordinateFromView:locationMap]; 
txtLatitude.text = [NSString stringWithFormat:@"%f",centre.latitude]; 
txtLongitude.text = [NSString stringWithFormat:@"%f",centre.longitude]; 

위도와 경도 모두 0으로 표시됩니다. 누구나 가질 수있는 아이디어에 감사드립니다!

============== - 업데이트 1-

오. 아래에 제안 된대로 :

NSLog(@"%@", locationMap); 

줄을 추가하면 로그에 "(null)"이 표시됩니다. 내가 (다른 것들 사이에) 내 헤더에 다음과 같은있어 :

#import <UIKit/UIKit.h> 
#import <MapKit/MapKit.h> 
#import <CoreLocation/CoreLocation.h> 

IBOutlet MKMapView *locationMap; 

@property (nonatomic, retain) IBOutlet MKMapView *locationMap; 

과 내 방법 파일에 다음

@synthesize locationMap; 

이것은 현재 경고 나 오류없이 컴파일된다. 내가 뻔한 것을 놓친 적이 있는지 궁금해하기 시작한거야?

답변

38

centerCoordinate 속성은 어떻게됩니까?

CLLocationCoordinate2D centre = [locationMap centerCoordinate]; 

centerCoordindate 속성이 모두 0 인 경우, 유효한 locationMap 포인터를 가지고 있는지 확인 - 목표 - C를 사용하면 오류없이 무기 호에 메시지를 보내 드릴 것입니다!

NSLog(@"%@", locationMap); 시도 - 즉 무기 호를 출력하는 경우, 당신은 아마 인터페이스 빌더에서 MKMapView에 mapLocation를 연결하는 잊어 버린 - 반환뿐만 아니라 제로

+0

내가 너무 것을 시도했습니다). – Haydn

+0

locationMap은 유효한 포인터입니까? __NSLog (@ "% @", locationMap);는 무엇을 말합니까? – deanWombourne

+0

감사합니다 - 로그는 "(null)"을 제공합니다 - 위의 업데이트를 참조하십시오. – Haydn

관련 문제