Ad
How To Use AutocompleteBounds In Swift 3
I want to use AutocompleteViewController in a special area with this Lat and Long
let SOUTHWEST_LATITUDE = 35.60;
let SOUTHWEST_LONGITUDE = 51.11;
let NORTHEAST_LATITUDE = 35.80;
let NORTHEAST_LONGITUDE = 51.60;
and now I don't know how to use them in my code!! here in my code
public func googlePlacesVC() -> UIViewController{
let autocompleteController = GMSAutocompleteViewController()
//how to use this ?
//autocompleteController.autocompleteBounds????
autocompleteController.delegate = self
return autocompleteController
}
Ad
Answer
You need define a GMSCoordinateBounds
with the southWest coordinate and the northEast coordinate, also you need to fix your constants declarations, statics constants are final already, also the type of the constant must be after the constant name, not before
UPDATE
Another thing you need to use autocompleteController.autocompleteBoundsMode = .restrict
if you want to restrict the results only to this bounds
Full Code
private static let SOUTHWEST_LATITUDE : Double = 35.60;
private static let SOUTHWEST_LONGITUDE : Double = 51.11;
private static let NORTHEAST_LATITUDE : Double = 35.80;
private static let NORTHEAST_LONGITUDE : Double = 51.60;
public func googlePlacesVC() -> UIViewController{
let autocompleteController = GMSAutocompleteViewController()
let northEastCoordinate = CLLocationCoordinate2D(latitude: ViewController.NORTHEAST_LATITUDE, longitude: ViewController.NORTHEAST_LONGITUDE)
let southWestCoordinate = CLLocationCoordinate2D(latitude: ViewController.SOUTHWEST_LATITUDE, longitude: ViewController.SOUTHWEST_LONGITUDE)
let bounds = GMSCoordinateBounds(coordinate: southWestCoordinate, coordinate: northEastCoordinate)
//how to use this ?
autocompleteController.autocompleteBounds = bounds
autocompleteController.autocompleteBoundsMode = .restrict
autocompleteController.delegate = self
return autocompleteController
}
this works, was tested ;)
Ad
source: stackoverflow.com
Related Questions
- → Function Undefined in Axios promise
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Click to navigate on mobile devices
- → Playing Video - Server is not correctly configured - 12939
- → How to allow api access to android or ios app only(laravel)?
- → Axios array map callback
- → Access the Camera and CameraRoll on Android using React Native?
- → Update React [Native] View on Day Change
- → Shopify iOS SDK - issue converting BuyProductVariant to BuyProduct
- → BigCommerce and shopify API
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → React Native - Differences between Android and IOS
- → What is the difference between React Native and React?
Ad