我有一个带有许多注释的地图视图。当用户点击注释时,它会将他们带到一个详细信息页面,其中包含有关艺术品的信息和一个“获取到此位置的路线”的按钮。所以这就是我要决定的。我刚刚使用的地图视图具有当前用户位置,这是我需要将 URL 中的起点发送到地图应用程序。最好将最近的 userLocation 坐标从地图视图传递到下一页,以便我可以在用户需要方向时使用它,或者我应该在下一页上启动一个新的 CLLocationManager 来获取用户的位置。另外,我尝试了后者,但无法从经理那里获得用户的位置。我所做的只是在界面中声明管理器:
CLLocationManager *manager;
“财产”它:
@property (nonatomic, retain) CLLocationManager *manager;
“合成”它:
@synthesize manager;
在 viewDidLoad 中执行此操作:
[manager startUpdatingLocation];
然后在“导航”IBAction 方法中执行此操作:
-(IBAction)navigate; {
CLLocationCoordinate2D start = manager.location.coordinate;
CLLocationCoordinate2D end = {[selectedArtPiece.latitude doubleValue], [selectedArtPiece.longitude doubleValue]};
[[UIApplication sharedApplication] openURL:[[NSURL alloc] initWithString: [NSString stringWithFormat:@"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f", start.latitude, start.longitude, end.latitude, end.longitude ]]];
}
“结束”最终为 0,0,所以我必须遗漏一些东西。
所以我的问题是:
1. 我对 CLLocationManager 做错了什么。
2.假设我什至可以使用它,您会建议这样做以获取当前位置,还是应该从以前的地图视图发送稍微过时(可能)的用户位置以用于方向?仅仅为了获得方向坐标而启动 CLLocationManager 是否值得花费电池和时间?
感谢您的任何反馈!