2012-01-17 9 views
0

私はxmlファイルを解析してコンテンツをuitablaviewに読み込むアプリケーションを開発しています。このxmlファイルには、トラックの場所、速度、緯度、経度に関する情報を含む地理空間データが含まれています。私がしたいことは、1つの行を選択して、トラックの位置を示す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

大麦、コードを電子メールで送信できますか? –

関連する問題