【发布时间】:2011-06-03 05:19:25
【问题描述】:
我正在打开地图应用程序以显示从我的代码从用户当前位置到目的地坐标的路线。我正在使用以下代码打开地图应用程序。当按下按钮时,我正在调用此代码。 getCurrentLocation 是一个返回最近更新位置的方法。
- (void)showDirectionsToHere {
CLLocationCoordinate2D currentLocation = [self getCurrentLocation]; // LINE 1
NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f",
currentLocation.latitude,
currentLocation.longitude,
destCoordinate.latitude,
destCoordinate.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
}
这里 LINE 1 中的 [self getCurrentLocation] 使用 CLLocationManager 确定当前位置并返回值。
注意:我还没有实现LINE1中的代码。我只是打算这样做。
我的问题是:
- 这是在调用地图应用时计算当前位置的好习惯吗?
-
[self getCurrentLocation] 会在调用openURL之前返回当前位置吗? - 我是否必须在打开地图应用程序之前确定当前位置?
我对这些事情有点困惑。请指导我。谢谢。
【问题讨论】:
标签: iphone ios google-maps core-location