【问题标题】:pass location data from uitableview to mapview将位置数据从 uitableview 传递到 mapview
【发布时间】:2012-02-12 06:48:31
【问题描述】:

我正在开发一个解析 xml 文件的应用程序,然后将内容填充到 uitablaview 中。此 xml 文件包含地理空间数据,其中包含有关某些卡车的位置、速度、纬度、经度的信息。我想做的是选择一行,然后打开一个带有 mkmapview 的详细视图,显示卡车的位置。

有谁知道如何在地图中加载所选行的经纬度?

最好的问候。

【问题讨论】:

    标签: ios uitableview ios4 mkmapview core-location


    【解决方案1】:

    您可以使用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
    

    例如,在您的 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 类必须实现 CLLocationCoordinate2D coordinate 属性。而在 viewDidLoad 中,您必须调用 mapView 上的 senterCoordinate... 方法,以使地图居中。

    - (void) viewDidLoad {
        [super viewDidLoad];
    
        ...
    
        [mapView setCenterCoordinate:self.coordinate animated:NO];
    }
    

    【讨论】:

    • 使用它可以显示位置吗?我显示地图的代码是下一个: - (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 区域 = {坐标,跨度}; [mapView setRegion:区域动画:TRUE]; mapView.frame = self.view.frame; }
    • 呃,我做不到...你介意看看我的代码吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-24
    相关资源
    最近更新 更多