我正在开发一个解析xml文件的应用程序,然后在uitablaview中填充内容。此xml文件包含地理空间数据,其中包含有关某些卡车的位置,速度,纬度和经度的信息。我想要做的是选择一行,然后用mkmapview打开一个详细视图,该视图显示卡车的位置。
有谁知道如何加载地图中所选行的纬度和经度?
最好的问候。
答案 0 :(得分:0)
您可以使用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中,您必须在senterCoordinate...
上调用mapView
方法,以使地图居中。
- (void) viewDidLoad {
[super viewDidLoad];
...
[mapView setCenterCoordinate:self.coordinate animated:NO];
}