Kağan Cenan
Kağan Cenan

Reputation: 41

Google AutoComplete Query in Swift

I am using a google maps auto complete query as you seen in the below I determine the bounds of autocomplete around my location but I am still getting a places so far from my location. I also check the bounds.southwest and bounds.northeast, they are also true but places are not arsounds here.

    var northRegion = CLLocationCoordinate2DMake((locationManager.location?.coordinate.latitude)!*1.0001, (locationManager.location?.coordinate.longitude)!*1.01)
    var southRegion = CLLocationCoordinate2DMake((locationManager.location?.coordinate.latitude)!*0.99, (locationManager.location?.coordinate.longitude)!*0.9999)

    var bounds = GMSCoordinateBounds(coordinate: northRegion, coordinate: southRegion)

    print(locationManager.location?.coordinate.latitude)
    print(locationManager.location?.coordinate.longitude)
    print(bounds.northEast)
    print(bounds.southWest)
    var filter = GMSAutocompleteFilter()
    filter.type = GMSPlacesAutocompleteTypeFilter.Geocode


    var yourLat = locationManager.location?.coordinate.latitude
    var yourLon = locationManager.location?.coordinate.longitude



    placesClient = GMSPlacesClient()

    placesClient?.autocompleteQuery("[YOUR TEXTFIELD'S TEXT HERE]", bounds: bounds, filter: filter, callback: { (result, error) -> Void in

        for item in result! {

            print(item.attributedFullText)
        }
    })

For example, my location is Istanbul and when I wrote this, I am getting Cape Town datas.

Upvotes: 2

Views: 3483

Answers (2)

Victor Alejandria
Victor Alejandria

Reputation: 120

Maybe a little late to answer but you can try using filter.country = countryCode, I use that to limit the result to just my country.

Upvotes: 1

Kağan Cenan
Kağan Cenan

Reputation: 41

OK I found this in GMSPlacesClient * @param bounds The bounds used to bias the results. This is not a hard restrict - places may still * be returned outside of these bounds. This parameter may be nil.

So autocomplete query can not filter the places in bounds way.

Upvotes: 1

Related Questions