mapView:viewForOverlay:没有被调用

时间:2011-05-23 16:16:53

标签: iphone mkmapview mkoverlay

嘿所有.....我知道这是一个重复的问题,但我仍然无法让它工作,我确信我错过了一些简单的事情。我在IB中设置了委托,并且调用了RegionDidChange,因此我知道mapView委托被连接起来了。但是,我无法显示任何叠加,甚至无法调用委托方法。这是代码:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

self.map.region = MKCoordinateRegionMakeWithDistance(
                                                    newLocation.coordinate, 
                                                    milesToMeters(radius),
                                                    milesToMeters(radius)
                                                    );
self.map.centerCoordinate = newLocation.coordinate;
circle = [MKCircle circleWithCenterCoordinate:newLocation.coordinate radius:50.];    

[self.map addOverlay:circle];
[locationManager stopUpdatingLocation];   

}

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {

NSLog(@"region did change");
}

- (MKOverlayView *)map:(MKMapView *)map viewForOverlay:(id <MKOverlay>)overlay {
NSLog(@"circling");

if ([overlay isKindOfClass:[MKCirlce class]])

{
MKCircleView *circleView = [[[MKCircleView alloc] initWithCircle:overlay] autorelease];
circleView.lineWidth = 1.0;
circleView.strokeColor = [UIColor redColor];

return circleView;
}
return nil;

}

非常感谢。朱

1 个答案:

答案 0 :(得分:1)

viewForOverlay委托方法未命名。它应该是:

- (MKOverlayView *)mapView:(MKMapView *)map 
            viewForOverlay:(id <MKOverlay>)overlay {

必须将其命名为mapView:viewForOverlay:(不是map:viewForOverlay:)。

您可以更改内部参数名称,但不能更改方法名称。

另外,在viewForOverlay方法中,MKCirlce应为MKCircle