开发者

mapView:viewForOverlay: not getting called

Hey all..... I know this is a duplicate question but I still cannot get it to work and Im sure Im missing something simple. I have set the delegate in IB and RegionDid开发者_JAVA百科Change gets called so I know the mapView delegate is hooked up. However I cannot display any overlay or even get the delegate method to be called. Here is the code:

- (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;

}

Many thanks. Jules


The viewForOverlay delegate method is not named right. It should be:

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

It must be named mapView:viewForOverlay: (not map:viewForOverlay:).

You can change the internal parameter names but not the method name.

Also, inside your viewForOverlay method, MKCirlce should be MKCircle.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜