【发布时间】:2010-11-10 23:15:39
【问题描述】:
好的,我正在尝试获得与 iPhone 地图应用程序在您点击当前位置按钮时相同的放大/位置更新功能。我正在使用从here 和here(Brad Smith 的帖子中的代码)找到的代码来完成大部分工作。所以我真正需要做的就是将地图围绕更新的当前位置居中,并在每次有更新时再放大一点。
现在我在测试 centerCoord 是否为空时遇到了一些困难。正如您从结果中看到的(如下所列),它由于某种我无法弄清楚的原因而崩溃。以下是相关代码:
- (void) showCurrentLocationButtonTapped {
NSLog(@"Showing current location.");
locController = [[LocationController alloc] init];
[mapView setShowsUserLocation:YES];
zoomTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(zoomToCurrentLocation) userInfo:nil repeats:YES];
}
- (void) zoomToCurrentLocation {
CLLocationCoordinate2D centerCoord = self.locController.currentLocation.coordinate;
NSLog(@"Checking if loc controller is null");
if (!self.locController) {
NSLog(@"centerCoord is null!");
}
NSLog(@"centerCoord: %@",centerCoord);
[mapView setCenterCoordinate:centerCoord zoomLevel:7 animated:YES];
}
这是控制台输出:
2010-11-10 14:56:11.002 App Name[5278:207] Showing current location.
2010-11-10 14:56:11.504 App Name[5278:207] Checking if loc controller is null
2010-11-10 14:56:11.505 App Name[5278:207] centerCoord: (null)
2010-11-10 14:56:12.004 App Name[5278:207] Checking if loc controller is null
2010-11-10 14:56:12.004 App Name[5278:207] centerCoord: (null)
2010-11-10 14:56:12.504 App Name[5278:207] Checking if loc controller is null
我知道我没有测试 centerCoord 的空值,但如果我这样做:
if (!centerCoord) {
我在该行收到一条错误消息:
MapViewController.m:55: error: wrong type argument to unary exclamation mark
【问题讨论】: