【发布时间】:2011-02-15 21:22:38
【问题描述】:
这是代码 - 它不言自明(具体参见代码中的@todo):
// Handle taps of certain table rows
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Set up start location
CLLocationCoordinate2D start;
// Initialize the location manager, to get user location
locationController = [[JJGCLController alloc] init];
locationController.delegate = self;
[locationController.locationManager startUpdatingLocation];
// @todo - Get the latitude/longitude values back from my controller, and
// set them as the start coordinates.
//start.latitude = location.coordinate.latitude;
//start.longitude = location.coordinate.latitude;
CLLocationCoordinate2D destination;
destination.latitude = (CLLocationDegrees)[pLatitude doubleValue];
destination.longitude = (CLLocationDegrees)[pLongitude doubleValue];
NSString *googleMapsURLString = [NSString stringWithFormat:@"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f",
start.latitude, start.longitude, destination.latitude, destination.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:googleMapsURLString]];
}
基本上,我正在尝试设置一个位置管理器/控制器来获取用户的位置,这样我就可以设置一个链接,该链接将在地图应用程序中打开,其中包含从用户位置到目的地(纬度/经度)的路线分别来自 pLatitude 和 pLongitude)。
我已经按照 Hello There: A Core Location Tutorial 添加我自己的位置控制器类 (JJGCLController),并且在我的视图控制器的 - (void)locationUpdate:(CLLocation *)location 方法中,我可以看到位置,但我无法获取坐标在我的 Table View 的 didSelectRowAtIndexPath 方法中。
基本上,我的应用在每个表格单元格中显示一个地址,当用户点击该地址时,我希望地图应用加载,然后出现从当前用户位置到该地址的路线。
【问题讨论】:
标签: iphone ios uitableview location cllocationmanager