Have you tried using DISPATCH_QUEUE_PRIORITY_BACKGROUND
instead of DISPATCH_QUEUE_PRIORITY_DEFAULT
?
Add MapKit Overlay to map x1 at a time from a for loop
-
23-06-2022 - |
質問
I have a dictionary loaded from a plist. I iterate over my array which contains a total of 4000 long and lats.
I process the for loop on a background thread using GCD (As it locks the UI while processing) and add the overlays in this task like the below.
All works ok except that the adding of all the overlays to the map only appear after the total array loop has finished. I would if I can like to iterate over the array and add x1 overlay at a time to the view rather than waiting for the total to process.
-(void)loadOverlays{
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Add code here to do background processing
int d;
for (d = 0; d < [[tempDict allValues]count]; d++) {
//Get values from dic
values = [tempDict allValues];
id aValue = [values objectAtIndex:d];
latCircle = [aValue objectAtIndex:1];
lngCircle = [aValue objectAtIndex:2];
geoFCenter = CLLocationCoordinate2DMake([latCircle floatValue], [lngCircle floatValue]);
geoFRadius = 10000.0; // 10,000 metres
//Add Zone circle
circle = [MKCircle circleWithCenterCoordinate:geoFCenter radius:geoFRadius];
[circle setTitle:@"2"];
[self.dragMap addOverlay:circle];
}
});
}
解決
所属していません StackOverflow