Question

What I do in my app is following:

I load some data into the core data and when that is finished app needs to segue to the next view (google map)

[self performSegueWithIdentifier:@"loadMap" sender:self];

but I get this error

Terminating app due to uncaught exception 'GMSThreadException', reason: 'All calls to the Google Maps SDK for iOS must be made from the UI thread'

If I do all of this but make a segue with tap on a button everything works fine.

Google map view controller in storyboard has one GMSMapView view outlet with init code

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:45.331875
                                                            longitude:14.450455
                                                                 zoom:14];

    self.mapView.camera = camera;

    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.position = camera.target;
    marker.title = @"Test title";
    marker.snippet = @"Lorem ipsum...";
    marker.map = self.mapView;

Can anybody help me here? How can I load view controller with google maps programmatically using storyboard?

Was it helpful?

Solution

The exception seems to be indicating that you're trying to perform a segue in the background thread. To stop it from crashing, you need to use the main thread instead. Wrap your performSegueWithIdentifier:sender: as follows to use the main thread:

dispatch_async(dispatch_get_main_queue(), ^{
    [self performSegueWithIdentifier:@"loadMap" sender:self];
});

OTHER TIPS

For Swift:

dispatch_async(dispatch_get_main_queue(), {})

Toss the code in those curlies...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top