2012-03-17 6 views
0

問題は、MapViewにポリラインを追加するときです...ポリラインがランダムな遅延で表示されました。時には1秒で5秒かかります。MKMapViewがオーバーレイを正しく更新しない、MKPolylineを表示するのが遅れる

ポリラインを描画する関数です。

- (void) setRoutePoints:(NSArray*)locations { 
    CLLocationCoordinate2D *pointsCoOrds = (CLLocationCoordinate2D*)malloc(sizeof(CLLocationCoordinate2D) * [locations count]); 
    NSUInteger i, count = [locations count]; 
    for (i = 0; i < count; i++) { 
     CLLocation* obj = [locations objectAtIndex:i]; 
     pointsCoOrds[i] = CLLocationCoordinate2DMake(obj.coordinate.latitude, obj.coordinate.longitude); 
    } 

    [mapView addOverlay:[MKPolyline polylineWithCoordinates:pointsCoOrds count:locations.count]]; 
    free(pointsCoOrds); 
} 

必要なコールバック関数は、(Appleのドキュメントを参照してください)も正しい

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay { 
    if ([overlay isKindOfClass:[MKPolyline class]]) { 
     MKPolylineView* routeLineView = [[MKPolylineView alloc] initWithPolyline:overlay]; 
     routeLineView.fillColor = [UIColor colorWithRed:0.0f green:0.0f blue:1.0f alpha:0.5f]; 
     routeLineView.strokeColor = [UIColor colorWithRed:0.0f green:0.0f blue:1.0f alpha:0.5f]; 
     routeLineView.lineWidth = 8; 
     return routeLineView; 
    } 
    return nil; 
} 

であり、これは、私が唯一の問題はということであるポリライン

[self setRoutePoints:steps]; 

を追加する関数を呼び出す方法ですポリラインがマップ上に描画される遅延はランダムです。私の問題を解決し

答えて

0

ソリューションは、メインスレッド上で

setTheRoutePoints 

関数を呼び出すことです。

これにより、ポリラインが表示された遅延がなくなりました。

[self performSelectorOnMainThread:@selector(setRoutePoints:) withObject:steps waitUntilDone:NO]; 
関連する問題