2012-12-27 2 views
4

내 응용 프로그램에는 MKMapView이 있으며 현재 보이는지도 영역의 중심 좌표를 가져 오려고합니다. 나는 다음과 같은 방법을 사용하여 사용자가 가시 영역을 움직이면 새로운 중심 좌표를 얻게됩니다.MKMapView centerLocation

- (void)mapView:(MKMapView *)mapView1 regionDidChangeAnimated:(BOOL)animated 
{ 

CLLocationCoordinate2D centre = [mapView centerCoordinate]; 

NSLog(@"MAP CENTER = %f,%f",centre.latitude,centre.longitude); 
} 

문제는 I가 두 회 MAP CENTER = 0.000000,0.000000 제공 MKMapView 포함 UIViewController 전환하면 다음 실제 좌표 MAP CENTER = 55.755786,37.617633을 제공한다는 것이다. 나는 그 좌표를 UIViewController으로 바꾸 자마자 실제 좌표를 원한다.

답변

3

좌표가 (55.755786,37.617633)입니까?

MKMapView은 현재 위치의 좌표를 가져 오기 위해 GPS에 잠글 때까지 약간의 시간이 걸립니다. 그때까지 centerCoordinate(0,0)

+0

을 반환 할 수 있습니다.이 코드는 'MKUserLocation * userLocation = userView.userLocation; MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance ( userLocation.location.coordinate, 500000, 500000); [mapView setRegion : 지역 애니메이션 : NO]; ' 이 코드를 제거하면'centerCoordinate'는'30.0000, -40.0000'입니다. 나는 그 중 하나도 원하지 않습니다. 잠시 동안이 문제를 극복하기 위해 정적'centerCoordinate '를 넣었습니다. –

1

이 방법을 사용해보십시오.

self.mapView.centerCoordinate = self.mapView.userLocation.location.coordinate;