Rounak Kiran
Rounak Kiran

Reputation: 11

GMSGeocoder reverseGeocodeCoordinate function not working on background thread

I'm trying to call reverseGeocodeCoordinate function from GMSGeocoder class from a background thread. But it is not working. The completion handler is not getting called. If I call the function from Main thread, it is working fine. But this approach is making the app slow sometimes as this function will be called continuously. Is there any way to call reverseGeocodeCoordinate function from background thread?

Below is my current code.

DispatchQueue.main.async {
                let geoCoder = GMSGeocoder()
                geoCoder.reverseGeocodeCoordinate((coordinate), completionHandler: {
                    reverseGeoCodeResponse, error in
                    // processing
                 }
}

This code works. But if I change DispatchQueue.main to DispatchQueue.global(), the completionHandler is not getting called. I want to call this API in background.

Upvotes: 1

Views: 370

Answers (1)

Abizern
Abizern

Reputation: 150605

Why not just call it from the main thread? It looks like the calls are sent on a background thread and the documentation says that the callback is called on the main thread.

You don't need to make the calls on a background thread, nor make sure that the completion is on the main thread.

Upvotes: 1

Related Questions