Migrating to Places 4.0 SDK, how to migrate place Bias?

Viewed 589

I am migrating to the new places SDK 4.0

The old func was:

findAutocompletePredictions(fromQuery: query,
                            bounds: bounds,
                            boundsMode: .bias,
                            filter: filter,
                            sessionToken: token) { (prediction, error) in
                                        callback(prediction, error)
}

the new func as per docs is

findAutocompletePredictions(fromQuery: query,
                            filter: filter,
                            sessionToken: token) { (prediction, error) in
                                        callback(prediction, error)
}

I see that bounds bias is now set on the GMSAutocompleteFilter filter

This has a locationBias property where i set some and it takes a parameter of <GMSPlaceLocationBias>

The issue i have is there is no info on what to provide here...GMSPlaceLocationBias is a protocol, and i have no idea what im meant to use object wise to provide the old bounds data.

Conforming to the protocol gives me a locationBiasURLQueryItem fun to populate, with no further documentation on what should go in this function

So im stuck and cant upgrade as there doesnt seem to be a clear way forward.

Anyone have any ideas? Docs are here: https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_places_client#ab60773feec0e68751c5a7f1066b9d252)

My attempt to construct the filter is:

    let filter = GMSAutocompleteFilter()
    if case .location(let location) = _locationController.locationStatus {
        filter.locationBias = .some(location)
    }

But obviously my custom location model object doesnt confirm to GMSPlaceLocationBias and is a struct so cant be used and errors

1 Answers

I got totally lost on this as well, but just found an example buried in one of the guides here.

In short the implementation looks like this:

let filter = GMSAutocompleteFilter()
filter.locationBias = GMSPlaceRectangularLocationOption(bounds.northEast, bounds.southWest)

Here I'm using the same bounds I had previously been using in 3.x (in my case from the map currently being displayed) to get those northEast and southWest coordinates, but you can generate your own based on how where you are trying to bias results.

I wish they had just made ANY indication in their docs that this was the intended way to do it.

Related