iosgoogle-mapsgoogle-street-view

No callback for Google Maps panorama request


I am new to the Google Maps SDK. I wrote a little test app that is able to show a map with routing, and a streetView panorama. This works fine, i.e. everything (the Google account, the API key, etc.) is probably setup correctly.
I now tried to get streetView pano metadata using

DispatchQueue.main.async {
    let panoramaService = GMSPanoramaService()
    panoramaService.requestPanoramaNearCoordinate(start) { pano, error in
        guard error == nil else { fatalError() }
    }
}

where start ist some coordinate.
I set breakpoints at the requestPanoramaNearCoordinate call, and at the guard statement in the callback. The 1st breakpoint is reached, but the 2nd not, i.e. there is no callback.
What could be the reason?


Solution

  • This was my fault:
    I initialized panoramaService as a variable local to the async block.
    As soon as requestPanoramaNearCoordinate was executed, this variable was deallocated, and the completion block was thus not called.
    The correct way is to declare let panoramaService as a property that is not deallocated. Then, the completion block is called, as expected.