如何通过 Google Maps iOS SDK 的块更新地图项

How do you update map items via a block for Google Maps iOS SDK

我正在尝试在完成块后用多边形更新我的 Google 地图:

[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;


    }];

documentation for GMSMapView 说:

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.

这可能适用于所有地图 类 和操作,而不仅仅是 GMSMapView

因此,您可能需要分派回主线程来更新您的线路,例如:

[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;
    });        
}];