GMSPlace 自动完成始终 return 相同的地点坐标
GMSPlace Auto Complete Always return same Place coordinate
自动完成的 return 始终给出相同的值。
func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
print("Place name: \(place.name)")
print("Place coordinate: \(place.coordinate)")
dismiss(animated: true, completion: nil)
}
这是我总是得到的值:
CLLocationCoordinate2D(latitude: -180.0, longitude: -180.0)
这是我用来调用 searchViewController 的代码:
func showSearchViewController() {
let autocompleteController = GMSAutocompleteViewController()
autocompleteController.delegate = self
// Specify the place data types to return.
let fields: GMSPlaceField = GMSPlaceField(rawValue: UInt(GMSPlaceField.name.rawValue))
autocompleteController.placeFields = fields
// Specify a filter.
let filter = GMSAutocompleteFilter()
filter.type = .address
autocompleteController.autocompleteFilter = filter
// Display the autocomplete view controller.
present(autocompleteController, animated: true, completion: nil)
}
要解决此问题,您需要在字段 GMSPlaceField
中指定您想要的数据。
例如,如果你想要你需要输入的名称和坐标:
let fields: GMSPlaceField = GMSPlaceField(rawValue: UInt(GMSPlaceField.name.rawValue) | UInt(GMSPlaceField.coordinate.rawValue))
autocompleteController.placeFields = fields
自动完成的 return 始终给出相同的值。
func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
print("Place name: \(place.name)")
print("Place coordinate: \(place.coordinate)")
dismiss(animated: true, completion: nil)
}
这是我总是得到的值:
CLLocationCoordinate2D(latitude: -180.0, longitude: -180.0)
这是我用来调用 searchViewController 的代码:
func showSearchViewController() {
let autocompleteController = GMSAutocompleteViewController()
autocompleteController.delegate = self
// Specify the place data types to return.
let fields: GMSPlaceField = GMSPlaceField(rawValue: UInt(GMSPlaceField.name.rawValue))
autocompleteController.placeFields = fields
// Specify a filter.
let filter = GMSAutocompleteFilter()
filter.type = .address
autocompleteController.autocompleteFilter = filter
// Display the autocomplete view controller.
present(autocompleteController, animated: true, completion: nil)
}
要解决此问题,您需要在字段 GMSPlaceField
中指定您想要的数据。
例如,如果你想要你需要输入的名称和坐标:
let fields: GMSPlaceField = GMSPlaceField(rawValue: UInt(GMSPlaceField.name.rawValue) | UInt(GMSPlaceField.coordinate.rawValue))
autocompleteController.placeFields = fields