I have implemented google maps place API GMSAutocomplete. It works fine. However, every time when I input a address number I see a lot of foreign addresses which are not relevant. I was wondering if it is possible to set a limit to the place API so the result only shows the addresses in a country? e.g. Canada?
In my button tapped func (to autocompleteViewController) I have:
let orderVC = GMSAutocompleteViewController()
orderVC.delegate = self
let fields: GMSPlaceField = GMSPlaceField(rawValue: UInt(GMSPlaceField.name.rawValue) |
UInt(GMSPlaceField.placeID.rawValue) | UInt(GMSPlaceField.coordinate.rawValue))!
orderVC.placeFields = fields
let filter = GMSAutocompleteFilter()
filter.type = .address
orderVC.autocompleteFilter = filter
present(orderVC, animated: true, completion: nil)
My viewdidLoad I have:
let camera = GMSCameraPosition.camera(withLatitude: 43.6532,
longitude: 79.3832,
zoom: zoomLevel)
mapView = GMSMapView.map(withFrame: view.bounds, camera: camera)
mapView.settings.myLocationButton = true
mapView.settings.compassButton = true
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
mapView.isMyLocationEnabled = true
My autocomplete function is:
func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
print("Place name: \(place.name ?? "placenameNil")")
print("Place ID: \(place.placeID ?? "placeIdNil")")
print("Place attributions: \(place.attributions)")
print("place cordinate: \(place.coordinate.latitude) \(place.coordinate.longitude)")
dismiss(animated: true, completion: nil)
}
Do I need something like "locationManager.distanceFilter = 500" or is there a recommended method?