我正在制作应用程序,我正在使用谷歌地图,在主页面有一个文本框,我在其中键入地址,但其打开全表与搜索结果,我想显示该文本框下面的结果表。
extension HomeLocationVC: GMSAutocompleteViewControllerDelegate{
// Handle the user's selection.
func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
let center = CLLocationCoordinate2D(latitude: place.coordinate.latitude, longitude: place.coordinate.longitude)
let position = CLLocationCoordinate2DMake(10, 10)
self.addressTextField.text = String(describing: place.formattedAddress!)
print("Place name: \(place.name)")
print("Place address: \(String(describing: place.formattedAddress))")
print("Place attributions: \(String(describing: place.attributions))")
camera = GMSCameraPosition.camera(withLatitude: (place.coordinate.latitude),
longitude: (place.coordinate.longitude),
zoom: zoomLevel)
self.mapView.clear()
self.marker = GMSMarker(position: position)
self.marker.position = center
self.marker.title = String(describing: place.formattedAddress!)
self.marker.map = self.mapView
self.marker.isTappable = true
dismiss(animated: true, completion: nil)
}
func viewController(_ viewController: GMSAutocompleteViewController, didFailAutocompleteWithError error: Error) {
// TODO: handle the error.
print("Error: \(error)")
dismiss(animated: true, completion: nil)
}
// User cancelled the operation.
func wasCancelled(_ viewController: GMSAutocompleteViewController) {
print("Autocomplete was cancelled.")
dismiss(animated: true, completion: nil)
}
}
@IBAction func changeValue(_ sender: UITextField) {
let acController = GMSAutocompleteViewController()
acController.delegate = self
present(acController, animated: true, completion: nil)
}