I'm trying to update my Google Map with a polygon after a completion block:
[self.apiClient getActivityByID:self.activityID completion:^(NSDictionary *activity) { self.currentPolyline.map = nil; GMSPath *path = [GMSPath pathFromEncodedPath:@"encodedPolyline"]; self.currentPolyline = [GMSPolyline polylineWithPath:path]; self.currentPolyline.map = self.mapView; }];
The documentation for GMSMapView
says:
GMSMapView can only be read and modified from the main thread, similar to all UIKit objects. Calling these methods from another thread will result in an exception or undefined behavior.
This probably applies to all map classes and operations, not just GMSMapView
specifically.
So, you probably need to dispatch back to the main thread to update your line, eg:
[self.apiClient getActivityByID:self.activityID completion:^(NSDictionary *activity) {
dispatch_async(dispatch_get_main_queue(), ^{
self.currentPolyline.map = nil;
GMSPath *path = [GMSPath pathFromEncodedPath:@"encodedPolyline"];
self.currentPolyline = [GMSPolyline polylineWithPath:path];
self.currentPolyline.map = self.mapView;
});
}];