【发布时间】:2011-07-19 10:52:53
【问题描述】:
我正在开发一个应用程序来显示特定邮政编码中可用的商店。我从当前位置开始。我的当前位置出现蓝色脉动点。当我输入邮政编码时,我可以在地图视图中显示注释。我有一个“当前位置”按钮,可以再次返回当前位置。但是第二次我没有得到蓝点?我怎么得到它,这是代码:
- (void)showCurrentLocation
{
self.mapView.showsUserLocation = YES;
GPSAnnotation *annotation = [[GPSAnnotation alloc] initWithCoordinate:self.mapView.userLocation.coordinate];
annotation.title = @"Location";
[self.mapView addAnnotation:annotation];
[annotation release];
MKCoordinateRegion zoomIn;
zoomIn.center.latitude = self.mapView.userLocation.coordinate.latitude;
zoomIn.center.longitude=self.mapView.userLocation.coordinate.longitude;
zoomIn.span.latitudeDelta = .1f;
zoomIn.span.longitudeDelta =.1f;
self.mapView.showsUserLocation = YES;
[self.mapView setRegion:zoomIn animated:TRUE];
}
// annotation view
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(GPSAnnotation *)annotation
{
if ([[annotation title] isEqualToString:@"Location"])
{
MKAnnotationView *annotationView=[[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil] autorelease];
annotationView = [self.mapView dequeueReusableAnnotationViewWithIdentifier:@"blueDot"];
annotationView.annotation = annotation;
return annotationView;
}
else if ([annotation isKindOfClass:[MKUserLocation class]])
{
return nil;
}
}
【问题讨论】:
-
为什么要将 GPSAnnotation 坐标设置为与用户位置相同? viewForAnnotation 方法必须给你编译器警告“控制到达非无效函数的结尾”。至少在方法的末尾添加
return nil;来解决这个问题。除此之外还有其他一些问题。 -
嗨安娜卡列尼娜,感谢您的回复。我尝试添加“return nil”,即使这样我第二个 tym 也没有得到 tat blue dot。
标签: iphone ipad ios4 mkmapview mkmapviewdelegate