【发布时间】:2012-03-15 23:23:03
【问题描述】:
我想在启动时将地图缩放到当前用户位置。我尝试在 viewDidLoad 处使用 mapView.userLocation.coordinate 检索用户位置,但返回的坐标为 (0,0),可能是因为 MapKit 在启动时没有“找到”用户位置。
我找到了实现方法 didUpdateToLocation 的解决方案。我做了以下事情:
- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
if ( hasZoomedAtStartUp == NO )
{
[self zoomAtStartUp]; // my method to zoom the map
hasZoomedAtStartUp = YES;
}
}
我在 .h 文件上创建的 hasZoomedAtStartUp 变量并在 ViewDidLoad 中使用 NO 对其进行了初始化。
这个解决方案工作正常,但我想知道是否有另一种方法可以做到这一点,而不需要 if 语句。该 IF 与启动相关,因此出于性能原因,我想将其删除。
【问题讨论】:
标签: iphone ios mkmapview core-location