gpt4 book ai didi

iphone - map 查看 :viewForOverlay: not getting called

转载 作者:行者123 更新时间:2023-12-03 21:19:36 28 4
gpt4 key购买 nike

嘿大家......我知道这是一个重复的问题,但我仍然无法让它工作,而且我确信我错过了一些简单的东西。我已经在 IB 中设置了委托(delegate),并且 RegionDidChange 被调用,所以我知道 mapView 委托(delegate)已连接。但是我无法显示任何覆盖,甚至无法调用委托(delegate)方法。这是代码:

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

}

非常感谢。朱尔斯

最佳答案

viewForOverlay 委托(delegate)方法的命名不正确。应该是:

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

它必须命名为mapView:viewForOverlay:(而不是map:viewForOverlay:)。

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

此外,在您的 viewForOverlay 方法中,MKCircle 应该是 MKCircle

关于iphone - map 查看 :viewForOverlay: not getting called,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6099976/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com