2017-05-30 52 views
0

我正在努力解決與MapKit有關的問題。MKOverlayRenderer剪切和模糊與變焦iOS

我創建了一個MKPolygon的列表,根據我的geofence的服務器數據。

+ (MKPolygon *)polygonFromPoints:(NSArray *)points interiorPolygons:(NSArray *)polygons{ 

    NSInteger numberOfCoordinates = [points count]; 
    CLLocationCoordinate2D *polygonPoints = malloc(numberOfCoordinates * sizeof(CLLocationCoordinate2D)); 

    NSInteger index = 0; 
    for (NSArray *pointArray in points) { 
      polygonPoints[index] = CLLocationCoordinate2DMake([pointArray[1] floatValue], [pointArray[0] floatValue]); 
      index++; 
    } 

    MKPolygon *polygon; 
    if (polygons) { 
     polygon = [MKPolygon polygonWithCoordinates:polygonPoints count:numberOfCoordinates interiorPolygons:polygons]; 
    } else { 
     polygon = [MKPolygon polygonWithCoordinates:polygonPoints count:numberOfCoordinates]; 
    } 

    free(polygonPoints); 
    return polygon; } 

,並將其添加到地圖作爲MKOverlayRender

- (MKOverlayRenderer *) mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay{ 

    if([overlay isKindOfClass: [MKCircle class]]){ 
     MKCircleRenderer *circleRender = [[MKCircleRenderer alloc] initWithCircle:(MKCircle *)overlay]; 
     circleRender.fillColor = [ [Common colorWithHexString:BlueGeoFence] colorWithAlphaComponent:0.3]; 

     return circleRender; 
    }else if([overlay isKindOfClass: [MKPolygon class]]){ 

     MKPolygonRenderer *polygonRenderer = [[MKPolygonRenderer alloc] initWithPolygon:(MKPolygon *)overlay]; 
     polygonRenderer.fillColor = [ [Common colorWithHexString:BlueGeoFence] colorWithAlphaComponent:0.3]; 

     return polygonRenderer; 
    } 

    return nil; 
} 

然而,當我放大或更改地圖的位置重疊是削減,並有某種模糊效果

enter image description here

enter image description here

不知道如何解決這個問題?

在此先感謝

回答

0

我有同樣的問題。問題的根源在於MKPolygon正在創建內部多邊形,而實際上並不是內部多邊形。檢查您的數據並確保您的內部多邊形座標實際上位於較大多邊形的範圍內。