2012-01-17 8 views
0

XML 파일을 구문 분석하는 앱을 개발 중입니다. 그런 다음 콘텐츠가 uitablaview에 채워집니다. 이 xml 파일에는 일부 트럭의 위치, 속도, 위도, 경도에 대한 정보가 포함 된 지형 공간 데이터가 들어 있습니다. 내가하고 싶은 일은 한 행을 선택한 다음 트럭의 위치를 ​​보여주는 mkmapview로 detailview를 여는 것입니다.uitableview에서지도 뷰로 위치 데이터를 전달합니다.

지도에서 선택한 행의 위도와 경도를로드하는 방법을 아는 사람이 있습니까?

감사합니다.

답변

0

당신은 CLLocationCoordinate2D coordinate 속성을 구현하기 위해 TableViewDelegate 클래스

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    CLLocationCoordinate2D coordinate = ... // Obtain coordinate from selected index path 
    YourMapViewController * controller = ... // initialize YourMapViewController 

    // Your YourMapViewController class has to implement coordinate property as CLLocationCoordinate2D 
    controller.coordinate = coordinate; 

    // This is an example case you are using navigation controller, it can be modal transition as well. 
    [self.navigationController pushViewController:controller animated:YES]; 
} 

귀하의 YourMapViewController 클래스가에, 그래서 예를 들어 MKMapView

// You specify lat,lng as coordinate and the map centers around it 
- (void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate animated:(BOOL)animated 

// You specify a region (center lat,lng and span) and the map centers and zooms appropriately 
- (void)setRegion:(MKCoordinateRegion)region animated:(BOOL)animated 

의 방법 중 하나를 사용할 수 있습니다. 그리고 viewDidLoad에서 mapViewsenterCoordinate... 메서드를 호출하여지도를 가운데에 배치해야합니다.

- (void) viewDidLoad { 
    [super viewDidLoad]; 

    ... 

    [mapView setCenterCoordinate:self.coordinate animated:NO]; 
} 
+0

그 위치를 표시 할 수 있습니까? 지도를 보여주는 내 코드는 다음 코드입니다. - (void) viewDidLoad { [super viewDidLoad]; mapView = [[MKMapView alloc] initWithFrame : self.view.bounds]; mapView.mapType = MKMapTypeStandard; CLLocationCoordinate2D coord = {위도 : 37.183843, 경도 : -3.689346}; // 이것은 행을 선택할 때 자동으로 얻고 자하는 것입니다. MKCoordinateSpan span = {latitudeDelta : 50, longitudeDelta : 50}; MKCoordinateRegion region = {coord, span}; [mapView setRegion : region animated : TRUE]; mapView.frame = self.view.frame; } –

+0

음 나는 그것을 할 수 없다 ... 내 코드를 살펴 본다면 괜찮습니까? –

+0

보리, 코드를 이메일로 보내 주시겠습니까? –

관련 문제