GMSGeocoder.reverseGeocodeCoordinate throws fatal error

1.2k Views Asked by At

When I try to reverse a coordinate which is somewhere in the South Atlantic Ocean,

let geocoder = GMSGeocoder.init()
let coordinate = CLLocationCoordinate2D.init(
    latitude: -33.724339999999998, 
    longitude: -15.996094000000001)

geocoder.reverseGeocodeCoordinate(coordinate) { (response, error) in 
  print(response)
})

fatal error: unexpectedly found nil while unwrapping an Optional value

Yes, I don't expect a response but it shouldn't fail with a fatal error, am I right?

Is that a normal behaviour for GMSGeocoder?

2

There are 2 best solutions below

1
On
geocoder.reverseGeocodeCoordinate(coordinate) {(response, error) in 

    if((response?) != nil){
        print(response)
    }

})
0
On

So I've experienced this weird crash as well while using reverse geocode of Google Map and since you haven't neither chosen a correct answer nor posted your own solution. I checked the production build of my app (From App Store) is working fine. I did try stashing my changes just to check what crap I did that causes this crash.

The log also states something like this:

Google Maps SDK for iOS requires GoogleMaps.bundle to be part of your target

Now for the solution, I have posted it too here: https://stackoverflow.com/a/45607775/3231194

Basically just try to update your pods and clean the project and the build, then you're good to go.