使用GMSMapView进行EXC_BAD_ACCESS

时间:2016-08-06 15:04:09

标签: ios xcode

我有一个让我疯狂的EXC_BAD_ACCESS !!我试图创建一个自定义GMSCircle,当我分配一个GMSMapView实例时,它会导致崩溃......

任何人都可以帮助我,这是代码:

...
@property (nonatomic, strong) GMSMapView *mapView;
@property (nonatomic, strong) PGCRadarCircle *circle;
...
_mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
...
 _circle = [PGCRadarCircle radarWithPosition:[PGCLocationManager instance].currentLocation.coordinate
                                                map:_mapView
                                                 radius:500];

PGCRadarCircle.h

...
@property (nonatomic, strong) GMSMapView* map;
...

- (id)initWithPosition:(CLLocationCoordinate2D)coordinate map:(GMSMapView*)mapView radius:(CLLocationDistance)radius {
    if (self = [super init])
    {
        self.numberOfPulse = 2;
        self.map = mapView;
        self.position = coordinate;
        self.radius = radius;
        self.fillColor = [UIColor colorWithWhite:1.0 alpha:0.5];
        self.strokeColor = [UIColor colorWithWhite:0.9 alpha:0.5];
        self.strokeWidth = 1;
        self.running = false;
        self.waves = [[NSMutableArray alloc] init];
        self.duration = 2;


        GMSCircle *wave = [GMSCircle circleWithPosition:self.position radius:0];
        wave.fillColor = _fillColor;
        wave.strokeColor = _strokeColor;
        wave.strokeWidth = _strokeWidth;
        wave.map = _map;  <--- EXC_BAD_ACCESS at this line

        [_waves addObject:wave];

        [self initWaves];
    }

    return self;
}

堆栈的截图:

screenshot

object

感谢。

2 个答案:

答案 0 :(得分:3)

此问题可能是因为您的坐标无效,请尝试检查一下:

if (CLLocationCoordinate2DIsValid(self.position)) {
    wave.map = _map;
}

答案 1 :(得分:0)

我有同样的问题。在将地图(GMSMapView)分配给GMSCircle之前设置圆半径后,我的EXC_BAD_ACCESS消失了。因此,请尝试在代码中放置self.map = mapView;行。我希望它能帮到你!