Iphone 获取didSelectRowAtIndexPath内的用户位置坐标(对于TableView单元格点击)

Iphone 获取didSelectRowAtIndexPath内的用户位置坐标(对于TableView单元格点击),iphone,ios,uitableview,location,cllocationmanager,Iphone,Ios,Uitableview,Location,Cllocationmanager,下面是代码——它本身就说明了问题(具体请参见代码中的@todo): 基本上,我正在尝试设置一个位置管理器/控制器来获取用户的位置,以便我可以设置一个链接,该链接将在地图应用程序中打开,其中包含从用户位置到目的地的路线(lat/lon分别来自pLatitude和pLongitude) 我遵循了Hello There:A Core Location教程添加了我自己的Location controller类(jjgclclcolcontroller),在我的视图控制器的-(void)locationU

下面是代码——它本身就说明了问题(具体请参见代码中的@todo):

基本上,我正在尝试设置一个位置管理器/控制器来获取用户的位置,以便我可以设置一个链接,该链接将在地图应用程序中打开,其中包含从用户位置到目的地的路线(lat/lon分别来自pLatitude和pLongitude)

我遵循了Hello There:A Core Location教程添加了我自己的Location controller类(jjgclclcolcontroller),在我的视图控制器的
-(void)locationUpdate:(CLLocation*)Location
方法中,我可以看到位置,但无法获得表视图的
didSelectRowAtIndexPath
方法中的坐标


基本上,我的应用程序在每个表单元格中显示一个地址,当用户点击地址时,我希望地图应用程序加载,然后是从当前用户位置到要显示的地址的路由。

在调用
-startUpdatingLocation
和访问位置数据之间至少需要一小段时间


有两种方法可以实现这一点-您可以更早地调用
startUpdatingLocation
(例如,当应用程序启动时,或当此特定视图出现时),或者您可以延迟将用户发送到地图应用程序,直到调用
locationUpdate:
,这可能会在不可预测的时间后发生。这两种方法都不理想。

我同意。您需要时间获取位置。是否必须将用户发送到Maps.app?在你的应用程序中使用MKMapView可行吗?@Mark-我的应用程序中已经有了一个MapView来定位地图上的某些地方,但我并不特别想添加任何关于路线和导航的内容,所以我更乐意将用户踢向地图。另外,@grahamparks-我决定在viewDidLoad中启动位置管理器,然后存储坐标供以后使用。不理想,但它正在工作。我只希望我能有我的蛋糕,也能吃。
// 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]];
}