gpt4 book ai didi

iphone - 在 didSelectRowAtIndexPath 中获取用户位置坐标(用于 TableView Cell 点击)

转载 作者:行者123 更新时间:2023-12-01 19:28:28 25 4
gpt4 key购买 nike

这是代码 - 它不言自明(具体参见代码中的@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]];
}

基本上,我正在尝试设置一个位置管理器/ Controller 来获取用户的位置,这样我就可以设置一个链接,该链接将在 map 应用程序中打开,其中包含从用户位置到目的地的路线(来自 pLatitude 和p经度,分别)。

我已经按照 Hello There: A Core Location Tutorial 添加我自己的位置 Controller 类 (JJGCLController),并在我的 View Controller 的 - (void)locationUpdate:(CLLocation *)location方法,我可以看到位置,但我无法获得我的 TableView 中的坐标 didSelectRowAtIndexPath方法。

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

最佳答案

调用 -startUpdatingLocation 之间至少需要有一小段时间。并有权访问位置数据。

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

关于iphone - 在 didSelectRowAtIndexPath 中获取用户位置坐标(用于 TableView Cell 点击),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5009651/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com